Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

In PHP, should we use "print" or "echo" and what is the difference?

user-image
Question added by Abdulmajed Ghazy Almutairi , Web developer , Ijarah Finance
Date Posted: 2016/05/23
Mohmmed Ibrahim Shah Ibrahim Shah
by Mohmmed Ibrahim Shah Ibrahim Shah , Software Engineer , Adex Group

We will use "echo" because it is more faster than "print".And it takes multiple parameter."echo" does not return any value on the other hand "print" return alway 1.

Monika Salvi
by Monika Salvi , Software developer , Faichi Solution PVT ltd

echo and print are both same, both used to output data on screen.

The difference is minor echo has no return value where as print hav return value 1 so it can be used in expression.

Also echo can take multiple arguments (very rare case in use)   where print takes single parameter.

Also echo is slightly faster than print.

 

shaheen soudagar
by shaheen soudagar , Web Designer/Developer , Triya Solutions

Both Echo and print are use to output data on the screen but echo has no return value whereas print has a return value of 1 so it can be used in expressions

echo can take multiple parameters while print can take one argument.

Suchithra V Nair
by Suchithra V Nair , Web Developer , CynBer Infotech

1.   print only takes one parameter, while echo can have multiple parameters.

     Example:

         echo 'foo', 'bar';   // Concatenates the 2 strings

         print('foo', 'bar'); // Fatal error

2.   print returns a value (1), so can be used as an expression.

     Example:

         $res = print('test');

         var_dump($res); //bool(true)

Note: If you're looking to evaluate the outcome of an output statement use print. If not, use echo.     

3.   echo is faster than print.

Muhammad Awais Qamar
by Muhammad Awais Qamar , Software Engineer , GoDigiSoft PVT LTD

echo and print are more or less the same. They are both used to output data to the screen.

The differences are small:

echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.

Echo = Outputs one or more strings separated by commas and No return value e.g. echo "String 1", "String 2"

Print = Outputs only a single string. Returns 1, so it can be used in an expression e.g. print "Hello" or, if ($expr && print "foo")

Mostafa El-Gaby
by Mostafa El-Gaby , FrontEnd Engineer , Vezeeta

Print can only be used for single argument but Echo can take more than one parameter

Jue Maria George
by Jue Maria George , Ios Developer , OMA Emirates

echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters  while print can take one argument. 

yogita mohane
by yogita mohane , project trainee , India Active Software Inc. Nagpur

yes we use.They both are use to print data on screen.

The main difference is echo has no return value and print has return value 1.

shoaib rana
by shoaib rana , HOD , Brotex Industries

Echo has no Return value while print has

Aya olwan
by Aya olwan , full stack web developer , Nerdizor

Both used to output data to user screen 

The differences  between :

echo has no return value  while print has 

echo can take multiple parameters but print take one 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.