The echo and print both are used for produce out put but the main difference between them is that echo has no returning value where as print has returning value as 1 so it can be used in expressions
Print
- The echo accepts the multiple arguments where as print accept as as the single arguments .
- echo is faster than print .
- print is rarely user in the php.
Example For Displaying echo and print :
Echo
<?php
$a = “My first code to php.”;
$b = “Learn php at phpinterviewquestions.evernews.online.”;
$x = 1;
$y = 2;
echo “<p>” . $a .” “. $b . “</p>”;
echo $x + $y;
?>
Output :
My first code to php. Learn php at phpinterviewquestions.evernews.online.
3
<?php
$a = “My first code to php.”;
$b = “Learn php at phpinterviewquestions.evernews.online.”;
$x = 1;
$y = 2;
print “<p> “. $a . “</p>”;
print “<p> “. $b . “</p>”;
echo $x + $y;
?>
Output :
My first code to php.
Learn php at phpinterviewquestions.evernews.online.
3