我使用RecursiveIteratorIterator遍歷多維數組,並希望能夠知道當前元素是否爲深度的最後一個子元素。我想過這個:RecursiveIteratorIterator最後一個子節點
$iterator = new RecursiveIteratorIterator($array,
RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $val) {
$next = clone $iterator;
$next->next();
$lastChild = ($next->getDepth() < $iterator->getDepth());
}
但RecursiveIteratorIterator說它不可複製。
@Bobby:爲什麼SPL標籤意義?這絕對是一個問題。 – 2010-09-28 09:55:49
@Dennis Haarbrink:SO標籤上只有42個問題,因此我不確定它是否爲這個問題增加了一些有價值的東西。我也不確定這是否不會與'[php]'本身同義,因爲我也沒有用'[mscoree]'或'[System-Data]'標記C#問題。但是這可能值得Meta的討論。 – Bobby 2010-09-28 10:01:55
我標記爲「PHP循環迭代最後孩子」,不明白你的意見。 – sod 2010-09-28 10:10:34