www.webdeveloper.com
Results 1 to 3 of 3

Thread: Concatenation :o

  1. #1
    Join Date
    Nov 2009
    Posts
    61

    Concatenation :o

    Which would be better for echoing:

    PHP Code:
    <?php echo "hello"." world"?>
    or
    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
    Location
    Ankh-Morpork
    Posts
    19,248
    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

    eBookworm.us

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



Recent Articles