3v4l.org

run code in 300+ 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 = 22
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/kah84
function name:  (null)
number of ops:  24
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        DO_ICALL                                         $4      
    3     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, ->22
         10    > > FE_FETCH_R                                       ~9      $8, !2, ->22
         11    >   ASSIGN                                                   !3, ~9
   50    12        CONCAT                                           ~11     !3, '+%28'
         13        INIT_FCALL                                               'implode'
         14        SEND_VAL                                                 '%2C'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $12     
         17        CONCAT                                           ~13     ~11, $12
         18        CONCAT                                           ~14     ~13, '%29'
         19        ECHO                                                     ~14
   51    20        ECHO                                                     '%0A'
   49    21      > JMP                                                      ->10
         22    >   FE_FREE                                                  $8
   52    23      > 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 = 28
Branch analysis from position: 28
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:  30
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
         19      > JMP                                                      ->28
   43    20    >   INIT_FCALL                                               'trim'
         21        SEND_VAR                                                 !2
         22        SEND_VAL                                                 '+-+'
         23        DO_ICALL                                         $12     
         24        ASSIGN                                                   !2, $12
   44    25        FETCH_DIM_W                                      $14     !3, !2
         26        ASSIGN_DIM                                               $14
         27        OP_DATA                                                  !0
   46    28    > > RETURN                                                   !3
   47    29*     > RETURN                                                   null

End of function traverse_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.9 ms | 1413 KiB | 20 Q