3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 'school' => [ 'college' => [ 'nursing' => ['n1a', 'n2a', 'n3a', 'n4a'], 'hrm' => ['h1a', 'h2a', 'h3a', 'h4a'], 'tourism' => ['t1a', 't2a', 't3a', 't4a'], 'it' => ['i1a', 'i2a', 'i3a', 'i4a'], ], 'senior' => [], ], 'business' => [ 'office' => [ 'dep1' => ['team1', 'team2'], 'dep2' => ['team1', 'team2'], 'dep3' => ['team1', 'team2'], 'dep4' => ['team1', 'team2'], ], ], ]; $result = []; $search = "hrm"; function searchItemsByKey($array, $key) { $retArr = []; if (is_array($array)) { if (!empty($array[$key])) { return $array[$key]; } foreach ($array as $val) { $retArr = array_merge($retArr, searchItemsByKey($val, $key)); } } return $retArr; } $temp = searchItemsByKey($array, 'hrm'); print_r($temp);die;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 61) Position 1 = -2
filename:       /in/qIXij
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array, !1 = $result, !2 = $search, !3 = $temp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   21     1        ASSIGN                                                       !1, <array>
   22     2        ASSIGN                                                       !2, 'hrm'
   36     3        INIT_FCALL                                                   'searchitemsbykey'
          4        SEND_VAR                                                     !0
          5        SEND_VAL                                                     'hrm'
          6        DO_FCALL                                          0  $7      
          7        ASSIGN                                                       !3, $7
   37     8        INIT_FCALL                                                   'print_r'
          9        SEND_VAR                                                     !3
         10        DO_ICALL                                                     
         11      > INIT_FCALL                                                   'exit'
         12*       DO_ICALL                                                     
   38    13*     > RETURN                                                       1

Function searchitemsbykey:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 22
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 23
filename:       /in/qIXij
function name:  searchItemsByKey
number of ops:  25
compiled vars:  !0 = $array, !1 = $key, !2 = $retArr, !3 = $val
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   25     2        ASSIGN                                                       !2, <array>
   26     3        TYPE_CHECK                                      128          !0
          4      > JMPZ                                                         ~5, ->23
   27     5    >   ISSET_ISEMPTY_DIM_OBJ                             1  ~6      !0, !1
          6        BOOL_NOT                                             ~7      ~6
          7      > JMPZ                                                         ~7, ->10
   28     8    >   FETCH_DIM_R                                          ~8      !0, !1
          9      > RETURN                                                       ~8
   30    10    > > FE_RESET_R                                           $9      !0, ->22
         11    > > FE_FETCH_R                                                   $9, !3, ->22
   31    12    >   INIT_FCALL                                                   'array_merge'
         13        SEND_VAR                                                     !2
         14        INIT_FCALL_BY_NAME                                           'searchItemsByKey'
         15        SEND_VAR_EX                                                  !3
         16        SEND_VAR_EX                                                  !1
         17        DO_FCALL                                          0  $10     
         18        SEND_VAR                                                     $10
         19        DO_ICALL                                             $11     
         20        ASSIGN                                                       !2, $11
   30    21      > JMP                                                          ->11
         22    >   FE_FREE                                                      $9
   34    23    > > RETURN                                                       !2
   35    24*     > RETURN                                                       null

End of function searchitemsbykey

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
227.09 ms | 2277 KiB | 17 Q