Jump to content

What is the difference between 'echo' & 'print'?


shah_ankitb

Recommended Posts

I have following data gathered from PHP Manualvoid echo ( string arg1 [, string argn...]) -> Output one or more strings--> It is not a function ,no need to use parentheses --> we can use it as Example:- $first = "Hello"; <?=$first; ?>int print ( string arg) -> Output a string-->Outputs arg. Returns 1, always. print() is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list. I have also visited --> http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 I would also want to know how echo is faster than print?If somebody explain the diffrence & how echo is faster than print with EXAMPLE then it will be more useful.Straight away, I am looking for perfect EXAMPLE which can diffrentiate both.

Link to comment
Share on other sites

The difference between echo and print is that echo can print more then one value. You can do this with echo:echo $var1, $var2, $var3;Which may be only marginally faster then doing this:echo $var1 . $var2 . $var3;only because it doesn't have to do the string concatenation operation, it just outputs.The reason the article said that echo is faster then print is because echo is not a function and so it doesn't have the overhead associated with a function. If you want to know more then that, then you're getting into the low-level operation of the language itself and what happens behind the scenes when you call a function.If you want to test for yourself which is faster, create a script to loop through several things and output things several different ways. Output the results of function calls, output the contents of arrays, variables, constants, literal values, concatenated strings, etc. Output several different things, put it in a loop that runs a million times, and use the time() function to time the execution using both echo and print. Even with a million operations you'll realize that the difference in speed is very small.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...