ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Abdulmajed Ghazy Almutairi , Web developer , Ijarah Finance
تاريخ النشر: 2016/05/23
Mohmmed Ibrahim Shah Ibrahim Shah
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل shoaib rana , HOD , Brotex Industries

Echo has no Return value while print has

Aya olwan
من قبل 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 

المزيد من الأسئلة المماثلة