Hey guys, I wanted to provide this description of print and echo.
Not my words...
Even though print() and echo() are essentially interchangeable most of the time, there is a
substantial difference between them. While print() behaves like a function with its own
return value (although it is a language construct), echo() is actually a language construct that
has no return value and cannot, therefore, be used in an expression.
However, I can't think of any possible uses where I can't use one and not the other.
Can anyone provide an example of using print() in an expression where you can't with echo()??
The real difference between echo and print, in terms of speed of execution, is to all intents and purposes negligible. There are much more time-consuming parts of most scripts which are far more worthy of optimisation effort.
Cecilia I was actually looking into this the other day. The difference in speed really wouldn't be noticeable. Echo() is slightly (and I do mean slightly) faster because it doesn't return a value like print() does. Personally I'm going to use echo() in my pages because it's one less letter to type then print() .. and yeah I'm really that lazy.
Although I still don't see the upside of using print instead of echo, I can at least conclude that using () after echo and print is completely and utterly useless. They, when working with frameworks, components or even large script, they take up more bytes and therefore, the script becomes larger and takes longer to process.
When I see people's scripts with;
echo ( 'My Echo' ); // and of course ... print ( 'My print (duh..)' );
I find it a excessive use of overhead. When compared,
echo 'My echo'; // and of course ... print 'My print (duh..)';
...is a lot more easier on the eyes, very much so if you're working between if/elseif/else, for, foreach, while, switch and other functions. Use () only when you absolutely need to. :)
And yes, echo processes just slightly better than print, but it isn't notable. Create your own script and test it out on your own server (or XAMP, WAMP) using;