3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_array_deep_value(array $array, array $levelKeys) { foreach ($levelKeys as $index => $key) { if (!key_exists($key, $array)) { throw new Exception("key $key not found at level index $index"); } $array = $array[$key]; } return $array; } $myArray = [ 'one' => [ 'two' => [ 'three' => [ 4 ] ] ] ]; $pathArrays = [ ['one', 'two', 'three'], ['one', 'two'], ['one'], ['two'] ]; foreach ($pathArrays as $pathArray) { try { var_export(get_array_deep_value($myArray, $pathArray)); } catch (Exception$e) { //echo $e->getMessage(); var_export(null); } echo "\n---\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Found catch point at position: 12
Branch analysis from position: 12
2 jumps found. (Code = 107) Position 1 = 13, Position 2 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
filename:       /in/rvhX9
function name:  (null)
number of ops:  20
compiled vars:  !0 = $myArray, !1 = $pathArrays, !2 = $pathArray, !3 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, <array>
   23     1        ASSIGN                                                   !1, <array>
   30     2      > FE_RESET_R                                       $6      !1, ->18
          3    > > FE_FETCH_R                                               $6, !2, ->18
   32     4    >   INIT_FCALL                                               'var_export'
          5        INIT_FCALL                                               'get_array_deep_value'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !2
          8        DO_FCALL                                      0  $7      
          9        SEND_VAR                                                 $7
         10        DO_ICALL                                                 
         11      > JMP                                                      ->16
   33    12  E > > CATCH                                       last         'Exception'
   35    13    >   INIT_FCALL                                               'var_export'
         14        SEND_VAL                                                 null
         15        DO_ICALL                                                 
   37    16    >   ECHO                                                     '%0A---%0A'
   30    17      > JMP                                                      ->3
         18    >   FE_FREE                                                  $6
   38    19      > RETURN                                                   1

Function get_array_deep_value:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/rvhX9
function name:  get_array_deep_value
number of ops:  25
compiled vars:  !0 = $array, !1 = $levelKeys, !2 = $key, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2      > FE_RESET_R                                       $4      !1, ->22
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->22
          4    >   ASSIGN                                                   !3, ~5
    5     5        INIT_FCALL                                               'key_exists'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $7      
          9        BOOL_NOT                                         ~8      $7
         10      > JMPZ                                                     ~8, ->19
    6    11    >   NEW                                              $9      'Exception'
         12        ROPE_INIT                                     4  ~11     'key+'
         13        ROPE_ADD                                      1  ~11     ~11, !2
         14        ROPE_ADD                                      2  ~11     ~11, '+not+found+at+level+index+'
         15        ROPE_END                                      3  ~10     ~11, !3
         16        SEND_VAL_EX                                              ~10
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $9
    8    19    >   FETCH_DIM_R                                      ~14     !0, !2
         20        ASSIGN                                                   !0, ~14
    4    21      > JMP                                                      ->3
         22    >   FE_FREE                                                  $4
   10    23      > RETURN                                                   !0
   11    24*     > RETURN                                                   null

End of function get_array_deep_value

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
223.23 ms | 1006 KiB | 16 Q