1--TEST-- 2SPL: RecursiveIteratorIterator and beginChildren/endChildren 3--FILE-- 4<?php 5 6class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator 7{ 8 function rewind() 9 { 10 echo "<ul>\n"; 11 parent::rewind(); 12 } 13 function beginChildren() 14 { 15 echo str_repeat(' ',$this->getDepth())."<ul>\n"; 16 } 17 18 function endChildren() 19 { 20 echo str_repeat(' ',$this->getDepth())."</ul>\n"; 21 } 22 function valid() 23 { 24 if (!parent::valid()) { 25 echo "<ul>\n"; 26 return false; 27 } 28 return true; 29 } 30} 31 32$arr = array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"); 33$obj = new RecursiveArrayIterator($arr); 34$rit = new RecursiveArrayIteratorIterator($obj); 35foreach($rit as $k=>$v) 36{ 37 echo str_repeat(' ',$rit->getDepth()+1)."$k=>$v\n"; 38} 39?> 40--EXPECT-- 41<ul> 42 0=>a 43 <ul> 44 0=>ba 45 <ul> 46 0=>bba 47 1=>bbb 48 </ul> 49 <ul> 50 <ul> 51 0=>bcaa 52 </ul> 53 </ul> 54 </ul> 55 <ul> 56 0=>ca 57 </ul> 58 3=>d 59<ul> 60