PHP遍历循环时回显结果
问题描述:
我是执行循环,内部循环中有数据处理功能.
I am execution loop and inside loop there is data processing function inside loop.
for($i = 0 ; $i <=680 ; $i = $i + 40)
{
$url = 'http://www.yelp.com/biz/franchino-san-francisco?start=80';
$root = yelp($url);
var_dump($root);
}
此循环执行需要很长时间,并且在整个循环结束时将在最后回显结果.
This loop takes long time to execute, and results are echoed at the end when entire loop completes.
如何在每次迭代期间回显结果?
How can I echo the result during each iteration?
实际上这里会发生什么?结果是否存储在缓冲区中,并在末尾回显或显示什么?
Actually what happens here? does to result are stored in buffer and at the end echoed or what?
答
PHP缓冲输出.
如果要立即将内容输出到浏览器,可以使用flush()
和ob_flush()
函数:
If you want to output stuff to the browser immediately you can use the flush()
and ob_flush()
functions:
for ($i = 0; $i <= 680; $i += 40) {
$url = 'http://www.yelp.com/biz/franchino-san-francisco?start=80';
$root = yelp($url);
var_dump($root);
flush();
ob_flush();
}