3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ [ 'name' => 'name0', 'sub' => [ ['name' => 'name0.0'], ['name' => 'name0.1'] ] ], [ 'name' => 'name1', 'sub' => [ ['name' => 'name1.0'], ['name' => 'name1.1'], ['name' => 'name1.2'] ] ] ]; function search(array $array, $name) { foreach ($array as $key => $entry) { if ($entry['name'] === $name) { return [$key]; } if (isset($entry['sub']) && $found_keys = search($entry['sub'], $name)) { return array_merge([$key], $found_keys); } } return null; } print_r(search($input, 'name0.0')); print_r(search($input, 'name0.1')); print_r(search($input, 'name1.0')); print_r(search($input, 'name1.1')); print_r(search($input, 'name1.2'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1hGr1
function name:  (null)
number of ops:  37
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   34     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'search'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'name0.0'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   35     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'search'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 'name0.1'
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
   36    15        INIT_FCALL                                               'print_r'
         16        INIT_FCALL                                               'search'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 'name1.0'
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
   37    22        INIT_FCALL                                               'print_r'
         23        INIT_FCALL                                               'search'
         24        SEND_VAR                                                 !0
         25        SEND_VAL                                                 'name1.1'
         26        DO_FCALL                                      0  $8      
         27        SEND_VAR                                                 $8
         28        DO_ICALL                                                 
   38    29        INIT_FCALL                                               'print_r'
         30        INIT_FCALL                                               'search'
         31        SEND_VAR                                                 !0
         32        SEND_VAL                                                 'name1.2'
         33        DO_FCALL                                      0  $10     
         34        SEND_VAR                                                 $10
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Function search:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 30
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/1hGr1
function name:  search
number of ops:  33
compiled vars:  !0 = $array, !1 = $name, !2 = $entry, !3 = $key, !4 = $found_keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2      > FE_RESET_R                                       $5      !0, ->30
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->30
          4    >   ASSIGN                                                   !3, ~6
   24     5        FETCH_DIM_R                                      ~8      !2, 'name'
          6        IS_IDENTICAL                                             !1, ~8
          7      > JMPZ                                                     ~9, ->11
   25     8    >   INIT_ARRAY                                       ~10     !3
          9        FE_FREE                                                  $5
         10      > RETURN                                                   ~10
   27    11    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~11     !2, 'sub'
         12      > JMPZ_EX                                          ~11     ~11, ->21
         13    >   INIT_FCALL_BY_NAME                                       'search'
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $12     !2, 'sub'
         16        SEND_FUNC_ARG                                            $12
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $13     
         19        ASSIGN                                           ~14     !4, $13
         20        BOOL                                             ~11     ~14
         21    > > JMPZ                                                     ~11, ->29
   28    22    >   INIT_FCALL                                               'array_merge'
         23        INIT_ARRAY                                       ~15     !3
         24        SEND_VAL                                                 ~15
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                         $16     
         27        FE_FREE                                                  $5
         28      > RETURN                                                   $16
   23    29    > > JMP                                                      ->3
         30    >   FE_FREE                                                  $5
   31    31      > RETURN                                                   null
   32    32*     > RETURN                                                   null

End of function search

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.08 ms | 1019 KiB | 20 Q