PHP Echo & print

In this tutorial, we will teach you how to use echo and print statements to display the result of php code.

In PHP, echo and print  both are language construct not actually a function. Therefore, there is no requirment of parenthesis.

Difference between echo and print

In Echo

  • echo is used to show the output of PHP code
  • It can be used with or without paranthesis. Like echo or echo().
  • echo has no return value.
  • we can pass multiple arguments by using comma (,) saparated.
  • echo is marginally faster than print.

Example of Echo:

<?php 

  echo "This is my first string"; 

  //pass multiple arguments by using comma (,) saparated
  echo "This","is","my","second","string";  


?>

 

In Print

  • print is also used to show the output of PHP code.
  • It can be used with or without paranthesis. Like print or print().
  • print has a return value of integer 1 so it can be used in expression.
  • print can take one argument. We can't pass multiple arguments.
  • print is slower than echo

Example of Print:

<?php 

  print "This is my first string"; 

?>