Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Abdulmajed Ghazy Almutairi , Web developer , Ijarah Finance
Date de publication: 2016/05/23
Mohmmed Ibrahim Shah Ibrahim Shah
par 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
par 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
par 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
par 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
par 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.

Utilisateur supprimé
par Utilisateur supprimé

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
par 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
par 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
par 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
par shoaib rana , HOD , Brotex Industries

Echo has no Return value while print has

Aya olwan
par 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