array_009a.phpt 659 B

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