fork download
  1. <?php
  2.  
  3. $tree = array(
  4. 0 => 100,
  5. 1 => 200,
  6. 2 => array(
  7. 0 => 7,
  8. 1 => 8,
  9. 2 => 9
  10. )
  11. );
  12.  
  13. function walkAroundTheTree(array &$branch)
  14. {
  15. foreach ($branch as &$node) {
  16. if (is_array($node)) {
  17. // Если у нас вложенный массив
  18. walkAroundTheTree($node);
  19. } else {
  20. // Если число
  21. $node = $node * 2;
  22. }
  23. }
  24. }
  25.  
  26. var_dump($tree);
  27. walkAroundTheTree($tree);
  28. var_dump($tree);
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  int(100)
  [1]=>
  int(200)
  [2]=>
  array(3) {
    [0]=>
    int(7)
    [1]=>
    int(8)
    [2]=>
    int(9)
  }
}
array(3) {
  [0]=>
  int(200)
  [1]=>
  int(400)
  [2]=>
  array(3) {
    [0]=>
    int(14)
    [1]=>
    int(16)
    [2]=>
    int(18)
  }
}