PHP Echo and Print Statements

PHP Echo and Print Statements

PHP echo and print both statements are used to display the output in a web browser. The differences between both is print has a return value while echo has no return value. And one another differnce between both is echo can take multiple parameters while print can take one argument. echo is slightly faster than print.

PHP echo Statement

<?php
// Display string
echo "Hello World!";
// Display HTML code
echo "<h3>This is a simple h3 heading.</h3>";
// Declare Variable
$txt = "Welcome to Webcodeschool.com";
// Display variable
echo $txt;
?>

PHP Print Statement

<?php
// Display string
print "Hello World!";
// Display HTML code
print "<h3>This is a simple h3 heading.</h3>";
// Declare Variable
$txt = "Welcome to Webcodeschool.com";
// Display variable
print $txt;
?>