Which would be better for echoing:
<?php echo "hello"." world"; ?>
From what I've heard, the second option is faster, as it doesn't concatenate the whole string then output it, but simply outputs it as it goes along. Is this right?
<?php echo "hello"," world"; ?>
I'm not aware that either is faster, but if it is, it's likely such a small difference as to be lost in all the other random factors that could affect the response time. While it is true that with "." the parts are first concatenated and then output by echo, on the other hand with "," each argument is processed separately by echo, so you may in effect be executing a separate echo on each, which might be less efficient. Or not. Like I said, it's the sort of thing I don't worry about when modern processors are so fast. Maybe if I had Facebook type traffic I'd do some benchmarking and find out. (But then, they're compiling their PHP into executables, so they probably don't worry about it, either.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Way back in the day the "," version was considerably faster (v3 or 4 mostly). Lately (v5 or better) there is such a minor difference between the two it really doesn't matter any more.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)