3v4l.org

run code in 500+ PHP versions simultaneously
<?php function paths(array $a) { // if first item is an array, recurse if (is_array(reset($a))) { foreach ($a as $k => $v) { foreach (paths($v) as $path) { // yield "key - subpath" yield sprintf('%s - %s', $k, $path); } } } else { // yield leaf yield sprintf('(%s)', implode(', ', $a)); } } $obj = json_decode('{ "Group1": { "Blue": { "Round": [ "Harold", "Arthur", "Tom" ] }, "Green": { "Round": [ "Harold" ], "Circle": [ "Todd", "Mike" ] } }, "Group2": { "Blue": { "Round": [ "Peter" ] } } }', true); foreach (paths($obj) as $path) { printf("%s\n", $path); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/1atQk
function name:  (null)
number of ops:  17
compiled vars:  !0 = $obj, !1 = $path
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     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'
   45     2        SEND_VAL                                                     <true>
   19     3        DO_ICALL                                             $2      
          4        ASSIGN                                                       !0, $2
   47     5        INIT_FCALL                                                   'paths'
          6        SEND_VAR                                                     !0
          7        DO_FCALL                                          0  $4      
          8      > FE_RESET_R                                           $5      $4, ->15
          9    > > FE_FETCH_R                                                   $5, !1, ->15
   48    10    >   INIT_FCALL                                                   'printf'
         11        SEND_VAL                                                     '%25s%0A'
         12        SEND_VAR                                                     !1
         13        DO_ICALL                                                     
   47    14      > JMP                                                          ->9
         15    >   FE_FREE                                                      $5
   49    16      > RETURN                                                       1

Function paths:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 24
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/1atQk
function name:  paths
number of ops:  30
compiled vars:  !0 = $a, !1 = $v, !2 = $k, !3 = $path
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        GENERATOR_CREATE                                             
    6     2        INIT_FCALL                                                   'reset'
          3        SEND_REF                                                     !0
          4        DO_ICALL                                             $4      
          5        TYPE_CHECK                                      128          $4
          6      > JMPZ                                                         ~5, ->24
    7     7    > > FE_RESET_R                                           $6      !0, ->22
          8    > > FE_FETCH_R                                           ~7      $6, !1, ->22
          9    >   ASSIGN                                                       !2, ~7
    8    10        INIT_FCALL_BY_NAME                                           'paths'
         11        SEND_VAR_EX                                                  !1
         12        DO_FCALL                                          0  $9      
         13      > FE_RESET_R                                           $10     $9, ->20
         14    > > FE_FETCH_R                                                   $10, !3, ->20
   10    15    >   ROPE_INIT                                         3  ~12     !2
         16        ROPE_ADD                                          1  ~12     ~12, '+-+'
         17        ROPE_END                                          2  ~11     ~12, !3
         18        YIELD                                                        ~11
    8    19      > JMP                                                          ->14
         20    >   FE_FREE                                                      $10
    7    21      > JMP                                                          ->8
         22    >   FE_FREE                                                      $6
    6    23      > JMP                                                          ->29
   15    24    >   FRAMELESS_ICALL_2                implode             ~15     '%2C+', !0
         25        ROPE_INIT                                         3  ~17     '%28'
         26        ROPE_ADD                                          1  ~17     ~17, ~15
         27        ROPE_END                                          2  ~16     ~17, '%29'
         28        YIELD                                                        ~16
   17    29    > > GENERATOR_RETURN                                             

End of function paths

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.43 ms | 2597 KiB | 17 Q