3v4l.org

run code in 500+ PHP versions simultaneously
<?php $obj = json_decode('{ "Group1": { "Blue": { "Round": [ "Harold", "Arthur", "Tom" ] }, "Green": { "Round": [ "Harold" ], "Circle": [ "Todd", "Mike" ] } }, "Group2": { "Blue": { "Round": [ "Peter" ] } } }', true); function traverse_array($array,$key="",$prev="",&$final_op=array()) { if(is_array($array)) { $prev .= $key." - "; foreach ($array as $key => $value) { traverse_array($value,$key,$prev,$final_op); } } else { $prev =trim($prev," - "); $final_op[$prev][]=$array; } return $final_op; } $data = traverse_array($obj); foreach ($data as $key => $value) { echo $key." (".implode(",", $value).")"; echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/kah84
function name:  (null)
number of ops:  21
compiled vars:  !0 = $obj, !1 = $data, !2 = $value, !3 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'json_decode'
          1        SEND_VAL                                                     '%7B%0A++++%22Group1%22%3A+%7B%0A++++++++%22Blue%22%3A+%7B%0A++++++++++++%22Round%22%3A+%5B%0A++++++++++++++++%22Harold%22%2C%0A++++++++++++++++%22Arthur%22%2C%0A++++++++++++++++%22Tom%22%0A++++++++++++%5D%0A++++++++%7D%2C%0A++++++++%22Green%22%3A+%7B%0A++++++++++++%22Round%22%3A+%5B%0A++++++++++++++++%22Harold%22%0A++++++++++++%5D%2C%0A++++++++++++%22Circle%22%3A+%5B%0A++++++++++++++++%22Todd%22%2C%0A++++++++++++++++%22Mike%22%0A++++++++++++%5D%0A++++++++%7D%0A++++%7D%2C%0A++++%22Group2%22%3A+%7B%0A++++++++%22Blue%22%3A+%7B%0A++++++++++++%22Round%22%3A+%5B%0A++++++++++++++++%22Peter%22%0A++++++++++++%5D%0A++++++++%7D%0A++++%7D%0A%7D'
   29     2        SEND_VAL                                                     <true>
    3     3        DO_ICALL                                             $4      
          4        ASSIGN                                                       !0, $4
   48     5        INIT_FCALL                                                   'traverse_array'
          6        SEND_VAR                                                     !0
          7        DO_FCALL                                          0  $6      
          8        ASSIGN                                                       !1, $6
   49     9      > FE_RESET_R                                           $8      !1, ->19
         10    > > FE_FETCH_R                                           ~9      $8, !2, ->19
         11    >   ASSIGN                                                       !3, ~9
   50    12        CONCAT                                               ~11     !3, '+%28'
         13        FRAMELESS_ICALL_2                implode             ~12     '%2C', !2
         14        CONCAT                                               ~13     ~11, ~12
         15        CONCAT                                               ~14     ~13, '%29'
         16        ECHO                                                         ~14
   51    17        ECHO                                                         '%0A'
   49    18      > JMP                                                          ->10
         19    >   FE_FREE                                                      $8
   52    20      > RETURN                                                       1

Function traverse_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kah84
function name:  traverse_array
number of ops:  27
compiled vars:  !0 = $array, !1 = $key, !2 = $prev, !3 = $final_op, !4 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      ''
          2        RECV_INIT                                            !2      ''
          3        RECV_INIT                                            !3      <array>
   33     4        TYPE_CHECK                                      128          !0
          5      > JMPZ                                                         ~5, ->20
   35     6    >   CONCAT                                               ~6      !1, '+-+'
          7        ASSIGN_OP                                         8          !2, ~6
   36     8      > FE_RESET_R                                           $8      !0, ->18
          9    > > FE_FETCH_R                                           ~9      $8, !4, ->18
         10    >   ASSIGN                                                       !1, ~9
   37    11        INIT_FCALL_BY_NAME                                           'traverse_array'
         12        SEND_VAR_EX                                                  !4
         13        SEND_VAR_EX                                                  !1
         14        SEND_VAR_EX                                                  !2
         15        SEND_VAR_EX                                                  !3
         16        DO_FCALL                                          0          
   36    17      > JMP                                                          ->9
         18    >   FE_FREE                                                      $8
   33    19      > JMP                                                          ->25
   43    20    >   FRAMELESS_ICALL_2                trim                ~12     !2, '+-+'
         21        ASSIGN                                                       !2, ~12
   44    22        FETCH_DIM_W                                          $14     !3, !2
         23        ASSIGN_DIM                                                   $14
         24        OP_DATA                                                      !0
   46    25    > > RETURN                                                       !3
   47    26*     > RETURN                                                       null

End of function traverse_array

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.48 ms | 2636 KiB | 15 Q