which one of the 2 have the best performance?
In javascript I was heard douglas crockford say that you shouldn’t use str += if you are concatenating a large string but use array.push instead.
I’ve seen lots of code where developers use $str .= to concatenate a large string in PHP as well, but since “everything” in PHP is based on arrays (try dumping an object), my thought was that the same rule applies for PHP.
Can anyone confirm this?
Strings are mutable in PHP so using .= does not have the same affect in php as using += in javascript. That is, you will not not end up with two different strings every time you use the operator.
See:
php String Concatenation, Performance
Are php strings immutable?