
Here’s a quick one: use echo when you output content, since it is faster that print.
Why is that? print() is a function, in fact and therefore it takes more time to process it.
So unless you have to output formatted content (in which case you’d use sprintf(), for example), just use echo. It is faster - and simpler.
If you would like to make a comment, please fill out the form below.
Everywhere else I have read that print is faster than echo. This includes the comments section of php.net.
Have you actually done any benchmarks to test this assertion ?
Incidentally, using single-quote strings is much faster than double-quote strings. The difference there is that double-quote strings are parsed for variables at run time.
Hmm.. I’ve read this somewhere, some long time ago, and since then, I’ve been using echo to output content in all my scripts. I’ll have to dig deeper for this problem. If I’m wrong, all my apologies, to Dave and all my readers - and thanks for noticing.
Just use whichever one you prefer, and whichever seems more appropriate and readable, as you won’t notice any difference, especially if eaccelerator / zend optimizer / any other bytecode optimizer comes into play (and it should, if you’re concerned with performance).