Archive

Posts Tagged ‘print’

Difference between php echo and print

June 25th, 2010

So I have been asked this question < ? php echo "a" , " million" , " times" , " over" ? > so I thought I would answer it on my wiki.

Although both these functions or more accurate known as language constructs (which is why you can use these without parenthesis() ) are pretty much the same, they have 2 key differences.

1. echo() can take multiple arguments (as mentioned above) so you don’t have to perform string concatenation on the variable(s) before passing in the value(s). Which is also a reason why echo is a little faster than print().

2. The other difference is that echo returns a void value or doesn’t return a value as apposed to print() returning a int value. This can be considered as a performance benefit. This feature also allows you to pass print() as a parameter to a echo command.

Although I thing to note, which can help you decide which one to use is that php by default uses echo when you use < ? = $var ? > syntax. Which probably means that echo is a better choice

admin PHP, Programming , , ,