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

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

متابعة

What is the difference between echo and print in PHP?

user-image
تم إضافة السؤال من قبل Samar Saleh , Community Manager , Bayt.com
تاريخ النشر: 2014/01/20
Muhammad Majid Saleem
من قبل Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

Most of differences already explained in above and below answers. Let me summerize them once again with one or more difference.

 

Following are few differences between echo and print:

SPEED:

Echo is speed wise faster than Print.

 

CONSTRUCTs:

Both are constructs but Print behaves like a function and it always returns1 whereas Echo just prints values / strings.

 

PARAMETERS:

Echo accepts more than1 parameters whereas Print accepts just1 parameter.

 

TERNARY OPERATION:

Echo can be used in Ternary Operation lik:

echo ( $var ) ? "Yes" : "No";

Print can also be used in Ternary Operation but with a different way like:

( $var ) ? print("Yes") : print("No");

Fadi Alkhateeb
من قبل Fadi Alkhateeb , Senior Front End Developer , NexTwo

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

- print returns a value (1), so can be used as a function.

- echo is slightly faster.

See PHP echo and print Statements

Zaid Rabab'a
من قبل Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.

In daily works i see no difference at all , but you can say their is an acutal diffrence like

Print is a function and always return1

Print take1 param , echo tacks multi, can print multiple strings,variables

echo is faster

 

هاشم المشارقة
من قبل هاشم المشارقة , Key Account Manager , Advanced United Systems Ltd. ( A member of Taj Holding Group)

Echo

  1. 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.
  2. echo does not return any value
  3. void echo ( string $arg1 [, string $... ] )
  4. In PHP, echo is not a function but a language construct.

 

Print 

  1. print only takes one parameter.
  2. print always returns1 (integer)
  3. int print ( string $arg )
  4. In PHP, print is not a really function but a language construct. However, it behaves like a function in that it returns a value.

Atif Aqeel
من قبل Atif Aqeel , Founder And Director , Xesense

There are some differences between echo and print:

  • echo - can output one or more strings
  • print - can only output one string, and returns always1

Muhammad Abid Saleem
من قبل Muhammad Abid Saleem , Software Engineer , PVT Company LTD lahore

In simple words.

Print is a function and always return someing else /1 always.

Echo is just used for display/get output of variable values / string

Renjith Chacko
من قبل Renjith Chacko , Offshore Web Developer , Design Master

Print is a function and it will return value, so takes time marginally. Whereas echo is a statement. Using echo we can display one or more strings whereas print will display the output of the string else error.

 

MANIKANTA AITHA
من قبل MANIKANTA AITHA

echo is language construct 

echo accepts more than one parameters at a time

where as print only one.

jagadeesh puthukkudi
من قبل jagadeesh puthukkudi , Frontend and backend Developer , QBurst

echo is language constructor .

print is function .

 

islam khalil
من قبل islam khalil , Technical Manager , iCloudit

The print is not a language construct whereas an echo statement is !

Speed. There is a difference between the two, but speed-wise it should be irrelevant which one you use. echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty.Expression. print() behaves like a function in that you can do: $ret = print "Hello World"; And $ret will be1. That means that print can be used as part of a more complex expression where echo cannot. An example from the PHP Manual:

Mohamed Hassan
من قبل Mohamed Hassan , Senior Application and Integration Developer , IBM

in your daily work nothing at all

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