A question about different methods of outputting html from PHP; what are the performance differences between these:
Method 1 - variable concatenation
$html = '';
$html .= '<ul>';
for ($k = 1; $k < = 1000; $k++){
$html .= '<li> This is list item #'.$k.'</li>';
}
$html .= '</ul>';
echo $html;
Method 2 - output buffering
ob_start();
echo '<ul>';
for ($k = 1; $k < = 1000; $k++){
echo '<li> This is list item #',$k,'</li>';
}
echo '</ul>';
I suspect you get some performance hit from continually modifying and enlarging a variable; is that correct?
Cheers!
Thanks GaryF, but I don't want an answer about architecture - this question is about performance. There seem to be some different opinions / testing about which one is faster, which is why there is not an accepted answer as yet.