1--TEST-- 2SPL: RecursiveTreeIterator and IteratorAggregate 3--FILE-- 4<?php 5 6$ary = array( 7 0 => array( 8 "a", 9 1, 10 ), 11 "a" => array( 12 2, 13 "b", 14 3 => array( 15 4, 16 "c", 17 ), 18 "3" => array( 19 4, 20 "c", 21 ), 22 ), 23); 24 25class RecursiveArrayIteratorAggregated implements IteratorAggregate { 26 public $it; 27 function __construct($it) { 28 $this->it = new RecursiveArrayIterator($it); 29 } 30 function getIterator(): Traversable { 31 return $this->it; 32 } 33} 34 35$it = new RecursiveArrayIteratorAggregated($ary); 36echo "-- flags = BYPASS_KEY --\n"; 37foreach(new RecursiveTreeIterator($it) as $k => $v) { 38 echo "[$k] => $v\n"; 39} 40echo "-- flags = BYPASS_CURRENT --\n"; 41foreach(new RecursiveTreeIterator($it, RecursiveTreeIterator::BYPASS_CURRENT) as $k => $v) { 42 echo "[$k] => $v\n"; 43} 44echo "-- flags = BYPASS_KEY|BYPASS_KEY --\n"; 45foreach(new RecursiveTreeIterator($it, RecursiveTreeIterator::BYPASS_CURRENT|RecursiveTreeIterator::BYPASS_KEY) as $k => $v) { 46 echo "[$k] => $v\n"; 47} 48echo "-- flags = 0 --\n"; 49foreach(new RecursiveTreeIterator($it, 0) as $k => $v) { 50 echo "[$k] => $v\n"; 51} 52echo "-- flags = 0, caching_it_flags = CachingIterator::CATCH_GET_CHILD --\n"; 53foreach(new RecursiveTreeIterator($it, 0, CachingIterator::CATCH_GET_CHILD) as $k => $v) { 54 echo "[$k] => $v\n"; 55} 56 57?> 58--EXPECTF-- 59-- flags = BYPASS_KEY -- 60[0] => |-Array 61[0] => | |-a 62[1] => | \-1 63[a] => \-Array 64[0] => |-2 65[1] => |-b 66[3] => \-Array 67[0] => |-4 68[1] => \-c 69-- flags = BYPASS_CURRENT -- 70 71Warning: Array to string conversion in %s on line %d 72[|-0] => Array 73[| |-0] => a 74[| \-1] => 1 75 76Warning: Array to string conversion in %s on line %d 77[\-a] => Array 78[ |-0] => 2 79[ |-1] => b 80 81Warning: Array to string conversion in %s on line %d 82[ \-3] => Array 83[ |-0] => 4 84[ \-1] => c 85-- flags = BYPASS_KEY|BYPASS_KEY -- 86 87Warning: Array to string conversion in %s on line %d 88[0] => Array 89[0] => a 90[1] => 1 91 92Warning: Array to string conversion in %s on line %d 93[a] => Array 94[0] => 2 95[1] => b 96 97Warning: Array to string conversion in %s on line %d 98[3] => Array 99[0] => 4 100[1] => c 101-- flags = 0 -- 102[|-0] => |-Array 103[| |-0] => | |-a 104[| \-1] => | \-1 105[\-a] => \-Array 106[ |-0] => |-2 107[ |-1] => |-b 108[ \-3] => \-Array 109[ |-0] => |-4 110[ \-1] => \-c 111-- flags = 0, caching_it_flags = CachingIterator::CATCH_GET_CHILD -- 112[|-0] => |-Array 113[| |-0] => | |-a 114[| \-1] => | \-1 115[\-a] => \-Array 116[ |-0] => |-2 117[ |-1] => |-b 118[ \-3] => \-Array 119[ |-0] => |-4 120[ \-1] => \-c 121