php - 为什么迭代以无限循环结束的 ArrayIterator?

标签 php infinite-loop arrayiterator

我代码中的数组很大,所以我将它粘贴到 pastebin 中。 http://pastebin.com/6tviT2Xj

我不明白为什么我会死循环

这个脚本的逻辑是:

$it = new ArrayIterator($options);
while($it->valid()) {
    print $it->key();
    print $it->current();
}

最佳答案

因为您永远不会在迭代器 ( with ArrayIterator::next() ) 中移动。

while ($it->valid()) {
    ...
    $it->next();
}

关于php - 为什么迭代以无限循环结束的 ArrayIterator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12709548/

相关文章:

PHPStorm 和 CodeIgniter 路由问题

c++ - 迭代器比数组 [i] 快吗?

c++ - 在 Release模式下编译时,大量嵌套循环会导致链接器无休止地运行吗?

python - 如何在循环已经运行时继续执行代码

java - “Using non reentrant iterator method: Array.iterator()” 错误消息是什么意思?

php - 如何使 ArrayIterator 或 ArrayObject 与 implode 一起工作?

php - 根据持续时间计算结束日期

PHP5 : Find Root Node in DOMDocument

php循环遍历多个数组

c++ - 为什么cout不显示字符串变量rnd?