In my current project I assemble one string out to many small strings (direct output is NOT an option). Would it be more efficient to do many string concatenations? or should I add the parts to an array and implode it?
First a side note - any of this does not matter in a real production application, as the time differences are superficial and the optimization of the application should be done in other places (dealing with network, database, filesystem, etc.). That being said, for curiosity's sake:
implode
may be more efficient concatenation, but only if you already have the array. If you don't, it probably would be slower since all the gain would be offset by the time needed to create the array and allocate its elements. So keep it simple :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With