Echo/Print in PHP

An echo/print in PHP is the output variable used to display values of your program on screen.

  • An echo is slightly different from print. The major difference is that an echo has a return value of 1 but a print has a return value of 0.
  • An echo is marginally faster or speedy than a print that’s why it can easily take multiple parameters in it. But a print can take only one argument at a time.

Echo in PHP

An echo in PHP can be used both as a statement and function like (echo, echo( ) ).

<!DOCTYPE html>
<html>
<body>

<?php
$var = "Study PHP";
echo "PHP is a free and open-source language<br>";
echo $var ;
?> 

</body>
</html>

Print in PHP

Similarly, a print in PHP is also used both as a statement and as a function like ( print, print( ) ).

<!DOCTYPE html>
<html>
<body>

<?php
$y = 9;
print "The number that we want is: ";
print $y;
?> 

</body>
</html>