3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getFromKeyPath(array $array, array $keys) { foreach ($keys as $index => $key) { if (!key_exists($key, $array)) { throw new Exception("key $key not found at level index $index"); } $array = $array[$key]; } return $array; } $array = ['a' => ['b' => ['c' => 'value'], 'd' => 3]]; $keys = ['a', 'b', 'c']; try { var_export(getFromKeyPath($array, $keys)); } catch (Exception $e) { echo $e->getMessage(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ne5hi
function name:  (null)
number of ops:  15
compiled vars:  !0 = $array, !1 = $keys, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   17     2        INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'getfromkeypath'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $5      
          7        SEND_VAR                                                 $5
          8        DO_ICALL                                                 
          9      > JMP                                                      ->14
   18    10  E > > CATCH                                       last         'Exception'
   19    11    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         12        DO_FCALL                                      0  $7      
         13        ECHO                                                     $7
   20    14    > > RETURN                                                   1

Function getfromkeypath:
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/ne5hi
function name:  getFromKeyPath
number of ops:  25
compiled vars:  !0 = $array, !1 = $keys, !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 getfromkeypath

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.98 ms | 1010 KiB | 16 Q