3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'key1' => [ 'key2' => [ 'key3' => 'YAY I GOT IT' ] ] ]; $keys = ['key1', 'key2', 'key3']; function findValueForKeys($data, $keys) { $key = array_shift($keys); if (is_array($data)) { if (array_key_exists($key, $data)) { if (is_array($data[$key])) { return findValueForKeys($data[$key], $keys); } return $data[$key]; } } return $data; }; echo "Searching... got the value: " . findValueForKeys($array, $keys);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R0Wls
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array, !1 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   26     2        INIT_FCALL                                               'findvalueforkeys'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      'Searching...+got+the+value%3A+', $4
          7        ECHO                                                     ~5
          8      > RETURN                                                   1

Function findvalueforkeys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/R0Wls
function name:  findValueForKeys
number of ops:  24
compiled vars:  !0 = $data, !1 = $keys, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !1
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
   15     6        TYPE_CHECK                                  128          !0
          7      > JMPZ                                                     ~5, ->22
   16     8    >   ARRAY_KEY_EXISTS                                         !2, !0
          9      > JMPZ                                                     ~6, ->22
   17    10    >   FETCH_DIM_R                                      ~7      !0, !2
         11        TYPE_CHECK                                  128          ~7
         12      > JMPZ                                                     ~8, ->20
   18    13    >   INIT_FCALL_BY_NAME                                       'findValueForKeys'
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $9      !0, !2
         16        SEND_FUNC_ARG                                            $9
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $10     
         19      > RETURN                                                   $10
   20    20    >   FETCH_DIM_R                                      ~11     !0, !2
         21      > RETURN                                                   ~11
   23    22    > > RETURN                                                   !0
   24    23*     > RETURN                                                   null

End of function findvalueforkeys

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.98 ms | 1005 KiB | 15 Q