PHP echo and print statements

  • In this tutorial you will learn how to use the PHP echo and print statements to display the output in a web browser.
  • PHP use then echo and print statement to display the output.

PHP have a two ways to get the output.

  • echo
  • print

Difference between `echo` and `print`:

echo print
This statement can pass multiple string separated by ','. It cannot pass multiple strings.
It doesnot return any values. It always return 1.
It is faster compared print. It is slower compared echo.

Example of echo:

Edit it yourself

<!DOCTYPE html>
<html>
<body>

<?php
  echo "<h2>Welcome phpicoder</h2>";
  echo "I'm PHP Debelopoer!<br>";
  echo "Hello ", "This ", "string ", "was ", "made ", "with multiple parameters.";
?>


</body>
</html>

Output of PHP echo

Edit it yourself

Welcome phpicoder

I'm PHP Debelopoer!

Hello This string was made with multiple parameters.

Example of print:

Edit it yourself

<!DOCTYPE html>
<html>
<body>

<?php
  print "<h2>Welcome webthestuff</h2>";
  print "I'm PHP Debelopoer!<br>";
  print "We are learn in PHP!";
?>

</body>
</html>

Output of PHP print

Edit it yourself

Welcome webthestuff

I'm PHP Debelopoer!

We are learn in PHP!

  • Previous
  • Next