echo
print
Mostly echo is used to print the output. There is no much more difference in between these two elements.Both are similar but the difference is very small i.e. print will return a value of 1 and the echo won’t return any value.
Echo can take multiple arguments, but print can take only one argument at a time. Echo process the arguments very faster than print.
[php]
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello welcome to SP Lessons";
echo ("I am learning the scripts in SP Lessons");
echo("<h2>I learned so many things form SP Lessons</h2>");
echo "Thanks to SP Lessons Team";
?>
</body>
</html>
[/php]
Output:
Below is an other example that displays variable including the text.
[php]
<!DOCTYPE html>
<html>
<body>
<?php
$sp="Simple Programming";
echo "Learn the Nice Scripts at SPLessons.com ";
echo "SP Lessons standards for : ".$sp." Lessons";
?>
</body>
</html>
[/php]
Output:
[php]
<!–Please click on Run button below to see the output–>
<!DOCTYPE html>
<html>
<body>
<?php
print "Hello welcome to SP Lessons";
print ("I am learning the scripts in SP Lessons");
print("<h2>I learned so many things form SP Lessons</h2>");
print "Thanks to SP Lessons Team";
?>
</body>
</html>
[/php]
Output:
Below example displays variable along with text.
[php]
<!DOCTYPE html>
<html>
<body>
<?php $sp = 20; $sp1 = 60;
echo "SP Lessons standards for : ".($sp+$sp1)."";?>
</body>
</html>
[/php]
Output: