echo and print in PHP- Tutorialpath

Difference between echo and print in PHP

  • PHP echo and print both are PHP Statement.
  • Both are used to display the output in PHP.

PHP echo statement

  1. echo is a statement i.e used to display the output. it can be used with parentheses echo or without parentheses echo.
  2. echo can pass multiple string separated as ( , )
  3. echo can output one or more string.
  4. echo doesn’t return any value
  5. echo is faster then print
  6. We can use ‘echo’ to output strings or variables.

For Example:

echo
echo

output:

echo output
echo output

For Example  (multiple argument)

output:

 

PHP print statement:

  1. Print is also a statement i.e used to display the output. it can be used with parentheses print( ) or without parentheses print.
  2. using print can doesn’t pass multiple argument.
  3. print always return 1.
  4. it is slower than echo.
  5. print can only output one string.

For Example:

Output:

For Example  (multiple argument)

Output:

Leave a Reply

Your email address will not be published.