xref: /PHP-8.3/ext/spl/tests/array_009a.phpt (revision b3e08881)
1--TEST--
2SPL: ArrayIterator implementing RecursiveIterator
3--FILE--
4<?php
5
6class MyRecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
7{
8    function hasChildren(): bool
9    {
10        return is_array($this->current());
11    }
12
13    function getChildren(): MyRecursiveArrayIterator
14    {
15        return new MyRecursiveArrayIterator($this->current());
16    }
17}
18
19$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3);
20
21$dir = new RecursiveIteratorIterator(new MyRecursiveArrayIterator($array), RecursiveIteratorIterator::LEAVES_ONLY);
22
23foreach ($dir as $file) {
24    print "$file\n";
25}
26
27?>
28--EXPECT--
291
3021
31221
32222
33231
343
35