Possible Duplicate:
Strin开发者_如何学编程g concatenation vs array implode in PHP
there are situations in which you build the string trough a function like:
$output = '';
if($something) $output .= '<div>foo</div>';
if($something_else) $output .= '<div>moo</div>';
...
echo $output;
Do you think it's better to use a array instead and implode it at the end?
$output = array();
if($something) $output[] = '<div>foo</div>';
if($something_else) $output[] = '<div>moo</div>';
...
echo implode("\n", $output);
Is it considered a better practice?
You will probably take a performance hit using arrays. It most cases it would be small enough not to cause a problem.
But it's hard to say because you provide no context whatsoever.
精彩评论