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); echo "Searching for: '$key' in: '" . print_r($data, true) . "'" . PHP_EOL; if (!is_array($data)) { return $data; } if (array_key_exists($key, $data)) { if (!is_array($data[$key])) { echo 'Got the last value. It is: ' . $data[$key] . PHP_EOL; return $data[$key]; } findValueForKeys($data[$key], $keys); } else { 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/eAGtv
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>
   41     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 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 40
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 33
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eAGtv
function name:  findValueForKeys
number of ops:  42
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      
   15     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !1
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
   17     6        ROPE_INIT                                     3  ~6      'Searching+for%3A+%27'
          7        ROPE_ADD                                      1  ~6      ~6, !2
          8        ROPE_END                                      2  ~5      ~6, '%27+in%3A+%27'
          9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $8      
         13        CONCAT                                           ~9      ~5, $8
         14        CONCAT                                           ~10     ~9, '%27'
         15        CONCAT                                           ~11     ~10, '%0A'
         16        ECHO                                                     ~11
   19    17        TYPE_CHECK                                  128  ~12     !0
         18        BOOL_NOT                                         ~13     ~12
         19      > JMPZ                                                     ~13, ->21
   21    20    > > RETURN                                                   !0
   24    21    >   ARRAY_KEY_EXISTS                                         !2, !0
         22      > JMPZ                                                     ~14, ->40
   26    23    >   FETCH_DIM_R                                      ~15     !0, !2
         24        TYPE_CHECK                                  128  ~16     ~15
         25        BOOL_NOT                                         ~17     ~16
         26      > JMPZ                                                     ~17, ->33
   28    27    >   FETCH_DIM_R                                      ~18     !0, !2
         28        CONCAT                                           ~19     'Got+the+last+value.+It+is%3A+', ~18
         29        CONCAT                                           ~20     ~19, '%0A'
         30        ECHO                                                     ~20
   30    31        FETCH_DIM_R                                      ~21     !0, !2
         32      > RETURN                                                   ~21
   33    33    >   INIT_FCALL_BY_NAME                                       'findValueForKeys'
         34        CHECK_FUNC_ARG                                           
         35        FETCH_DIM_FUNC_ARG                               $22     !0, !2
         36        SEND_FUNC_ARG                                            $22
         37        SEND_VAR_EX                                              !1
         38        DO_FCALL                                      0          
   24    39      > JMP                                                      ->41
   37    40    > > RETURN                                                   !0
   39    41    > > RETURN                                                   null

End of function findvalueforkeys

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
256.93 ms | 1010 KiB | 16 Q