• PHP is not a function; it is a language construct and its output become one or more string.
  • If you want to pass more than one parameter to echo, the use of parentheses is required.
  • PHP echo statement is used to print the string, array, variable multi-line strings, escaping characters, etc.
  • Echo is used to display the output, because it is a statement and does not return any value.
  • Echo can be used with echo () or without parentheses echo.
  • In echo, we can pass multiple strings separated by a comma (,).
  • The PHP print can be used alternative to echo many times and its statement is similar to the echo statement.
  • In PHP print accepts one argument at a time & cannot be used as a variable function.
  • Echo is faster than the print statement and print outputs only the strings.
  • The main difference between the echo and print statement is that echo does not behave like function whereas print behave like a function.

Sample Code : Echo Statement

<!DOCTYPE html>
<html>
<body>

<?php
echo "<h2>PHP is Fun!</h2>";
echo "Welcome to wikitechy!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>

</body>
</html>

Output

Sample Code: Print Statement

<!DOCTYPE html>
<html>
<body>

<?php
$txt1 = "Learn PHP";
$txt2 = "Wikitechy.com";
$x = 5;
$y = 5;

print "<h2>" . $txt1 . "</h2>";
print "Study PHP at " . $txt2 . "<br>";
print $x + $y;
?>

</body>
</html>

Output

Categorized in: