3v4l.org

run code in 500+ PHP versions simultaneously
<?php $menu = [ 'root' => [ 'items' => [ 'A' => [ 'p' => [1, 2, 9], ], 'B' => [ 'p' => [1, 2, 3, 9], ], 'C' => [ 'p' => [1, 2, 4, 9], ], 'D' => [ 'items' => [ 'D1' => [ 'p' => [1, 2, 3, 4, 9], ], 'D2' => [ 'p' => [1, 2, 3, 4], ], ], ], 'E' => [ 'items' => [ 'E1' => [ 'p' => [1, 2, 10], ], ], ], 'F' => [ 'items' => [ 'F1' => [ 'p' => [5, 6], ], 'F2' => [ 'p' => [7, 8], ], ], ], ], ], ]; function recursive_ps($elem) { $output = []; if (isset($elem['items'])) { foreach($elem['items'] as $key => $value) { if (isset($value['p'])) { $output = array_merge($output, $value['p']); } if (isset($value['items'])) { // merge the return value of function $output = array_merge($output, recursive_ps($value)); } } } return $output; } $output = array_values(array_unique(recursive_ps($menu['root']))); print_r($output);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SE3uB
function name:  (null)
number of ops:  16
compiled vars:  !0 = $menu, !1 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   61     1        INIT_FCALL                                                   'array_values'
          2        INIT_FCALL                                                   'array_unique'
          3        INIT_FCALL                                                   'recursive_ps'
          4        FETCH_DIM_R                                          ~3      !0, 'root'
          5        SEND_VAL                                                     ~3
          6        DO_FCALL                                          0  $4      
          7        SEND_VAR                                                     $4
          8        DO_ICALL                                             $5      
          9        SEND_VAR                                                     $5
         10        DO_ICALL                                             $6      
         11        ASSIGN                                                       !1, $6
   62    12        INIT_FCALL                                                   'print_r'
         13        SEND_VAR                                                     !1
         14        DO_ICALL                                                     
         15      > RETURN                                                       1

Function recursive_ps:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 26
Branch analysis from position: 16
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 28
filename:       /in/SE3uB
function name:  recursive_ps
number of ops:  30
compiled vars:  !0 = $elem, !1 = $output, !2 = $value, !3 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   RECV                                                 !0      
   47     1        ASSIGN                                                       !1, <array>
   48     2        ISSET_ISEMPTY_DIM_OBJ                             0          !0, 'items'
          3      > JMPZ                                                         ~5, ->28
   49     4    >   FETCH_DIM_R                                          ~6      !0, 'items'
          5      > FE_RESET_R                                           $7      ~6, ->27
          6    > > FE_FETCH_R                                           ~8      $7, !2, ->27
          7    >   ASSIGN                                                       !3, ~8
   50     8        ISSET_ISEMPTY_DIM_OBJ                             0          !2, 'p'
          9      > JMPZ                                                         ~10, ->16
   51    10    >   INIT_FCALL                                                   'array_merge'
         11        SEND_VAR                                                     !1
         12        FETCH_DIM_R                                          ~11     !2, 'p'
         13        SEND_VAL                                                     ~11
         14        DO_ICALL                                             $12     
         15        ASSIGN                                                       !1, $12
   53    16    >   ISSET_ISEMPTY_DIM_OBJ                             0          !2, 'items'
         17      > JMPZ                                                         ~14, ->26
   55    18    >   INIT_FCALL                                                   'array_merge'
         19        SEND_VAR                                                     !1
         20        INIT_FCALL_BY_NAME                                           'recursive_ps'
         21        SEND_VAR_EX                                                  !2
         22        DO_FCALL                                          0  $15     
         23        SEND_VAR                                                     $15
         24        DO_ICALL                                             $16     
         25        ASSIGN                                                       !1, $16
   49    26    > > JMP                                                          ->6
         27    >   FE_FREE                                                      $7
   59    28    > > RETURN                                                       !1
   60    29*     > RETURN                                                       null

End of function recursive_ps

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.42 ms | 2091 KiB | 18 Q