2
Taking into account the codes below:
$str = '';
for ($i = 30000; $i > 0; $i--) {
$str .= 'STRING QUALQUER, ';
}
$str = subtr($str,0,-2);
and that
$sArr = array();
for ($i = 30000; $i > 0; $i--) {
$sArr[] = 'STRING QUALQUER';
}
$str = implode(", ",$sArr);
Taking performance into account, which form will have the least processing cost?
I found in a legacy code these two ways to do the same thing.
memory_limit
is a factor? through my search I found nothing, in the PHP manual about implode() and subter() only shows usage detailing.
At this link says making implode "usually takes twice as long as the standard concatenation operator", but substr() would also have to traverse the string to make the cut, correct?
Related: Explanation about concatenation of variables in PHP
Test with replace and implode
– rray