【发布时间】:2010-09-22 11:12:35
【问题描述】:
我最近看到了很多ob_get_clean()。通常我已经完成了$test .= 'test'
我想知道一个是否比另一个更快和/或更好。
这是使用ob_get_clean()的代码:
ob_start();
foreach($items as $item) {
echo '<div>' . $item . '</div>';
}
$test = ob_get_clean();
这是使用$test .= 'test'的代码:
$test = '';
foreach($items as $item) {
$test .= '<div>' . $item . '</div>';
}
哪个更好?
【问题讨论】:
-
我最近也一直在想这个。不知道答案,但我知道你错过了“echo $test;”关于后者...
-
第一个不回显变量。只需将整个 echo'd out 部分放入 $test。如果您喜欢,请投票:)
标签: php optimization concatenation