fork download
  1. <?php
  2.  
  3. $tree = [
  4. 1,
  5. 2,
  6. [
  7. 3,
  8. 3
  9. ],
  10. [
  11. 4,
  12. 4, [
  13. 41,
  14. 42
  15. ]
  16. ],
  17. 5
  18. ];
  19.  
  20. $notVisited = $tree;
  21.  
  22. while ($notVisited) {
  23. $currentElement = array_shift($notVisited);
  24. if (is_array($currentElement)) {
  25. $notVisited = array_merge($currentElement, $notVisited);
  26. } else {
  27. var_dump($currentElement);
  28. }
  29. }
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
int(1)
int(2)
int(3)
int(3)
int(4)
int(4)
int(41)
int(42)
int(5)