【发布时间】:2014-07-02 19:15:33
【问题描述】:
当使用\RecursiveIteratorIterator 的实例进行递归迭代时,在寻找深度大于当前深度的子迭代器时,它是否总是返回null?
请看:RecursiveIteratorIterator::getSubIterator
public RecursiveIterator RecursiveIteratorIterator::getSubIterator ([ int $level ])
例子:
$innerIterator = new \RecursiveArrayIterator([/*a recursive array*/]);
$iterator = new \RecursiveIteratorIterator($innerIterator);
foreach ($iterator as $value) {
$depth = $iterator->getDepth();
$parentDepth = $depth - 1;
$childDepth = $depth + 1;
// returns \RecursiveArrayIterator
$iterator->getSubIterator($depth);
// returns null first iteration and \RecursiveArrayIterator thereafter
$iterator->getSubIterator($parentDepth);
// always returns null...should it?
$iterator->getSubIterator($childDepth);
}
【问题讨论】: