The question is about various methods for outputting html from PHP; what are the differences in performance between them:
Method 1 - Concatenate Variables
$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 are getting some performance hit from constantly modifying and increasing the variable; it is right?
Hooray!
Thanks to GaryF, but I don't need an answer about architecture - this question is about performance. It seems that there are several different opinions / tests that go faster, so there is no answer yet.
source
share