In this tutorial you will learn echo and print statements, use of echo and print to display output in browser as well as difference between PHP echo and print.

php-tutorial-for-echo-and-print-difference

In the previous tutorial that is Day 3 ( Tutorial for PHP Echo and Print) program, We learnt that what is variable , type of variable and scope of variable in PHP. And Now it is Day 4 tutorial, where we will learn use and difference of  PHP Echo and Print statement.

PHP Echo / Print statement:- 

  • echo() and print() are not function but language constructs in PHP.
  • Have two basic ways to get output.
  • echo and print both are the same which display the output on the screen

I.  Learn about PHP echo statement:-

  • echo is a statement used to display result on screen. It can be used with parentheses or without parentheses.
  • With parentheses: echo()
  • Without parentheses: echo.

Example of PHP echo statement:-

 

You will get OUTPUT below when you execute above program:-

PHP is echo!

Hello friends !
I’m about to learn PHP!
This string was made with multiple parameters.

II.  Learn about PHP print statement:

  • Print statement also used to display result on the screen. It can also use with or without parentheses.

Example of PHP print statement:-

You will get OUTPUT below when you execute above program:-

PHP is print!

Hello world!
I’m about to learn PHP!

Difference between Echo and Print :-
difference between echo and print

 

Echo statement

Print statement

  • echo can take more than one parameter when used without ­parentheses.
  • The syntax is echo expression [, expression [, expression] … ].
  • Note: that echo ($arg1,$arg2) is invalid.

print only takes one parameter.

It is faster than print

it is slower than echo

­ Using Echo can pass multiple string separated by ( , )

using print we cannot pass multiple argument

echo does not return any value

print always return 1 (integer)

 

Our Previous tutorials of PHP :-

<<<<< PHP tutorial for beginner Day 3 –  variable scope and type of variable

<<<<< PHP tutorial for beginner Day 2 – Syntax overview and tag

<<<<< PHP tutorial for beginner Day 1 – Introduction and Installation.