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)) { return findValueForKeys($data[$key], $keys); } } 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/cZhmW
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>
   23     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 = 17
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/cZhmW
function name:  findValueForKeys
number of ops:  19
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, ->17
   16     8    >   ARRAY_KEY_EXISTS                                         !2, !0
          9      > JMPZ                                                     ~6, ->17
   17    10    >   INIT_FCALL_BY_NAME                                       'findValueForKeys'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_DIM_FUNC_ARG                               $7      !0, !2
         13        SEND_FUNC_ARG                                            $7
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $8      
         16      > RETURN                                                   $8
   20    17    > > RETURN                                                   !0
   21    18*     > RETURN                                                   null

End of function findvalueforkeys

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.45 ms | 1005 KiB | 15 Q