Saturday 10 September 2016

What is the difference between echo and print?

The major differences between print and echo are:

1) echo is a language construct while print is a function
2) echo can take multiple parameters while print can't take multiple parameters

3) echo just outputs the contents to screen while print returns true on successful output and false if unable to output. In this sense we usually says that print returns value while echo don't.

4) echo is faster than print in execution because it does not return values.
5) Last but not least, echo has 4 chars where as print has 5 chars.
Ex:
echo $str." test ".$ing;                                                 <---                 Concatenation slows down the process, since, PHP must add strings together.

echo "and a ", 1, 2, 3; echo "<br/>"; echo $test;     <---                  Calling Echo multiple times is not good as using Echo parameters in solo.

echo "and a ", 1, 2, 3,"<br/>",$test;                           <---                 Correct! In a large loop, this could save a couple of seconds in the long run!

$ret = print $testw;

No comments:

Post a Comment

Your comment is so valuable as it would help me in my growth of knowledge.