Although the answer is almost definately "it doesn't matter". When using echo in PHP is it better to write:
echo $string1 . "-" . $string2;
echo $string1 , "-" , $string2;
I understand that the first is doing string concatenation and the second is using the echo function's multi parameter version although does the echo funcion print multiple strings more efficiently (in terms of space and time)? As in would the echo function have to address additional space to store a concatenated form? If it doesn't and outputs sequentially then does that make the second variant slower as 3 sequential outputs may be slower than 1 concatenation where extra memory is addressed followed by only 1 output (the concatenated string)...
I know this is a really small thing but I was just curious....
I can't address your memory issues, but somebody already addressed performance issues here:
Here is my view of it. While comma "concatenation" is slightly faster (maybe 1-3 milliseconds over 100 operations), this is such an inconsequential drop in the bucket that the performance benefit isn't worth renouncing echo's more universal dot concatenation.
TLDR; comma's are (slightly quicker) but choose dot concatenation for easier-to-understand code
Ah ok thanks MK!!! I had a feeling the commas might be faster due to the fact that it may not have to address new memory for the concatenation but wasn't sure. In all honesty though is commas that confusing? Like c'mon people...
But as I expected not much of a difference.. Thanks for the link though! twas a good read
I'll be honest... I've got 4-5 years PHP experience and had never seen the commas. If I saw them in a piece of code they would seriously throw me off. Well they would, had I even noticed them!
Before I read the rest of your post I didn't know what was different between your two pieces of code because I didn't notice the commas. They would definitely throw me off.
Well the reason I was pasting the docs, is because you shouldn't use commas for concatenation period. It may not work in the future (since it isn't technically a feature). It is also awkward for other developers.
So for the most part, the answer is, it doesn't really matter which is faster, don't use either. If you're iterating that big of a dataset, and it's too slow, you shouldn't be using PHP in the first place. Go or something would be a better option.