3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a['abc']['def']['ghi'] = 'meukee!'; function getArrayValueByKeys(array $array, $key, ...$keys) { if (!isset($array[$key])) throw new Exception; if(is_array($array[$key])) return getArrayValueByKeys($array[$key], ...$keys); return $array[$key]; } function getArrayValueByKeysMS(array $array, array $keys, $depth = 0) { $key = $keys[$depth]; if (!isset($array[$key])) throw new Exception; if(is_array($array[$key])) return getArrayValueByKeysMS($array[$key], $keys, $depth+1); return $array[$key]; } echo getArrayValueByKeys($a, ...['abc', 'def', 'ghi']); echo getArrayValueByKeysMS($a, ['abc', 'def', 'ghi']); echo getArrayValueByKeys($a, ...['ddd', 'def', 'ghi']);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/01TuQ
function name:  (null)
number of ops:  22
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   FETCH_DIM_W                                      $1      !0, 'abc'
          1        FETCH_DIM_W                                      $2      $1, 'def'
          2        ASSIGN_DIM                                               $2, 'ghi'
          3        OP_DATA                                                  'meukee%21'
   29     4        INIT_FCALL                                               'getarrayvaluebykeys'
          5        SEND_VAR                                                 !0
          6        SEND_UNPACK                                              <array>
          7        CHECK_UNDEF_ARGS                                         
          8        DO_FCALL                                      1  $4      
          9        ECHO                                                     $4
   31    10        INIT_FCALL                                               'getarrayvaluebykeysms'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 <array>
         13        DO_FCALL                                      0  $5      
         14        ECHO                                                     $5
   33    15        INIT_FCALL                                               'getarrayvaluebykeys'
         16        SEND_VAR                                                 !0
         17        SEND_UNPACK                                              <array>
         18        CHECK_UNDEF_ARGS                                         
         19        DO_FCALL                                      1  $6      
         20        ECHO                                                     $6
         21      > RETURN                                                   1

Function getarrayvaluebykeys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/01TuQ
function name:  getArrayValueByKeys
number of ops:  23
compiled vars:  !0 = $array, !1 = $key, !2 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_VARIADIC                                    !2      
    7     3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      !0, !1
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->9
    8     6    >   NEW                                              $5      'Exception'
          7        DO_FCALL                                      0          
          8      > THROW                                         0          $5
   10     9    >   FETCH_DIM_R                                      ~7      !0, !1
         10        TYPE_CHECK                                  128          ~7
         11      > JMPZ                                                     ~8, ->20
   11    12    >   INIT_FCALL_BY_NAME                                       'getArrayValueByKeys'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $9      !0, !1
         15        SEND_FUNC_ARG                                            $9
         16        SEND_UNPACK                                              !2
         17        CHECK_UNDEF_ARGS                                         
         18        DO_FCALL                                      1  $10     
         19      > RETURN                                                   $10
   13    20    >   FETCH_DIM_R                                      ~11     !0, !1
         21      > RETURN                                                   ~11
   14    22*     > RETURN                                                   null

End of function getarrayvaluebykeys

Function getarrayvaluebykeysms:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/01TuQ
function name:  getArrayValueByKeysMS
number of ops:  26
compiled vars:  !0 = $array, !1 = $keys, !2 = $depth, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
   18     3        FETCH_DIM_R                                      ~4      !1, !2
          4        ASSIGN                                                   !3, ~4
   19     5        ISSET_ISEMPTY_DIM_OBJ                         0  ~6      !0, !3
          6        BOOL_NOT                                         ~7      ~6
          7      > JMPZ                                                     ~7, ->11
   20     8    >   NEW                                              $8      'Exception'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $8
   22    11    >   FETCH_DIM_R                                      ~10     !0, !3
         12        TYPE_CHECK                                  128          ~10
         13      > JMPZ                                                     ~11, ->23
   23    14    >   INIT_FCALL_BY_NAME                                       'getArrayValueByKeysMS'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $12     !0, !3
         17        SEND_FUNC_ARG                                            $12
         18        SEND_VAR_EX                                              !1
         19        ADD                                              ~13     !2, 1
         20        SEND_VAL_EX                                              ~13
         21        DO_FCALL                                      0  $14     
         22      > RETURN                                                   $14
   25    23    >   FETCH_DIM_R                                      ~15     !0, !3
         24      > RETURN                                                   ~15
   26    25*     > RETURN                                                   null

End of function getarrayvaluebykeysms

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.27 ms | 1403 KiB | 16 Q