array_009a.phpt 635 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. SPL: ArrayIterator implementing RecursiveIterator
  3. --FILE--
  4. <?php
  5. class MyRecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
  6. {
  7. function hasChildren()
  8. {
  9. return is_array($this->current());
  10. }
  11. function getChildren()
  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. ===DONE===
  23. <?php exit(0); ?>
  24. --EXPECT--
  25. 1
  26. 21
  27. 221
  28. 222
  29. 231
  30. 3
  31. ===DONE===