![]() |
print() vs echo()
Hey guys, I wanted to provide this description of print and echo.
Not my words... Quote:
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()?? TIA.... |
Quite simple:
PHP Code:
|
Using print as an if condition isn't a particularly useful example since it always returns 1. An example where echo cannot be used, where print can, is:
PHP Code:
|
thanks guys....seems like print and echo are still very very closely related to each other...
hopefully I won't run into any issues where I would require print and not echo..... |
Ive been wondering about something between these two. I think I read somewhere that echo is processed faster than print. Is this true?
|
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; PHP Code:
PHP Code:
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; PHP Code:
ReSpawN |
Another thing to note is that echo accepts multiple parameters where as print does not.
Some people prefer to pass multiple string's to echo in multiple parameters rather than concatenation. PHP Code:
|
Another good point made for echo sketchMedia. I forgot that one although I use it daily. Exactly as print can be used to print out variables with cutoffs, only echo allows for multiple parameters.
Currently I still prefer to set control the output, then parse it, and then output is using my own template engine or SMARTY (using {$name} in HTML) |
| All times are GMT. The time now is 09:31 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0