3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['foo' => ['bar' => 'lol', 'asdf' => ['rofl', ['haha' => 'lmao'], 'lawl']], ['hehe' => 'haha']]; function getLeafsWithKeys(array $array, array $keys = []): array { $result = []; foreach ($array as $key => $value) { $new_keys = is_numeric($key) ? $keys : array_merge($keys, [$key]); if (is_array($value)) { $result = array_merge([], ...[$result, getLeafsWithKeys($value, $new_keys)]); } else { $result[implode(' > ', $new_keys)][] = $value; } } return $result; } print_r(getLeafsWithKeys($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kWZUW
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   19     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'getleafswithkeys'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function getleafswithkeys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 42
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 42
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
Branch analysis from position: 34
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/kWZUW
function name:  getLeafsWithKeys
number of ops:  47
compiled vars:  !0 = $array, !1 = $keys, !2 = $result, !3 = $value, !4 = $key, !5 = $new_keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    6     2        ASSIGN                                                   !2, <array>
    7     3      > FE_RESET_R                                       $7      !0, ->42
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->42
          5    >   ASSIGN                                                   !4, ~8
    8     6        INIT_FCALL                                               'is_numeric'
          7        SEND_VAR                                                 !4
          8        DO_ICALL                                         $10     
          9      > JMPZ                                                     $10, ->12
         10    >   QM_ASSIGN                                        ~11     !1
         11      > JMP                                                      ->18
         12    >   INIT_FCALL                                               'array_merge'
         13        SEND_VAR                                                 !1
         14        INIT_ARRAY                                       ~12     !4
         15        SEND_VAL                                                 ~12
         16        DO_ICALL                                         $13     
         17        QM_ASSIGN                                        ~11     $13
         18    >   ASSIGN                                                   !5, ~11
    9    19        TYPE_CHECK                                  128          !3
         20      > JMPZ                                                     ~15, ->34
   10    21    >   INIT_FCALL                                               'array_merge'
         22        SEND_VAL                                                 <array>
         23        INIT_ARRAY                                       ~16     !2
         24        INIT_FCALL_BY_NAME                                       'getLeafsWithKeys'
         25        SEND_VAR_EX                                              !3
         26        SEND_VAR_EX                                              !5
         27        DO_FCALL                                      0  $17     
         28        ADD_ARRAY_ELEMENT                                ~16     $17
         29        SEND_UNPACK                                              ~16
         30        CHECK_UNDEF_ARGS                                         
         31        DO_ICALL                                         $18     
         32        ASSIGN                                                   !2, $18
    9    33      > JMP                                                      ->41
   13    34    >   INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '+%3E+'
         36        SEND_VAR                                                 !5
         37        DO_ICALL                                         $20     
         38        FETCH_DIM_W                                      $21     !2, $20
         39        ASSIGN_DIM                                               $21
         40        OP_DATA                                                  !3
    7    41    > > JMP                                                      ->4
         42    >   FE_FREE                                                  $7
   16    43        VERIFY_RETURN_TYPE                                       !2
         44      > RETURN                                                   !2
   17    45*       VERIFY_RETURN_TYPE                                       
         46*     > RETURN                                                   null

End of function getleafswithkeys

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.73 ms | 1010 KiB | 18 Q