我正在使用RecursiveArrayIterator处理this array:
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator($array),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $key => $item) {
//not working
//echo $iterator->getDepth() . "\n";
}
在使用该类进行数组时,是否可以获得当前深度?
答案 0 :(得分:0)
由于我的数据来自XML源,我能够用以下方法解决我的问题:
$sxi = new RecursiveIteratorIterator(
new SimpleXMLIterator($xml),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($sxi as $key => $value) {
$currentDepth = $sxi->getDepth();
}