Results 1 to 3 of 3

Thread: Concatenation :o

  1. #1
    Join Date
    Nov 2009

    Concatenation :o

    Which would be better for echoing:

    PHP Code:
    <?php echo "hello"." world"?>
    PHP Code:
    <?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?

  2. #2
    Join Date
    Aug 2004
    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.)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Jan 2009
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center