3v4l.org

run code in 500+ PHP versions simultaneously
<?php function findInArray(array $query, array $data) { foreach ($query as $key) { if (!array_key_exists($key, $data)) { // The key was not found, abort and return null return null; } // Since the key was found, move to next level $data =& $data[$key]; } return $data; } // Example response $response = [ 'client1' => [ 'dog' => [ 'Jack' => 'Some value', ], ] ]; // Define the query as an array $query = ['dog', 'Jack']; $result = findInArray($query, $response['client1']); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WjXTn
function name:  (null)
number of ops:  12
compiled vars:  !0 = $response, !1 = $query, !2 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                       !0, <array>
   27     1        ASSIGN                                                       !1, <array>
   29     2        INIT_FCALL                                                   'findinarray'
          3        SEND_VAR                                                     !1
          4        FETCH_DIM_R                                          ~5      !0, 'client1'
          5        SEND_VAL                                                     ~5
          6        DO_FCALL                                          0  $6      
          7        ASSIGN                                                       !2, $6
   31     8        INIT_FCALL                                                   'var_dump'
          9        SEND_VAR                                                     !2
         10        DO_ICALL                                                     
         11      > RETURN                                                       1

Function findinarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/WjXTn
function name:  findInArray
number of ops:  15
compiled vars:  !0 = $query, !1 = $data, !2 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    4     2      > FE_RESET_R                                           $3      !0, ->12
          3    > > FE_FETCH_R                                                   $3, !2, ->12
    5     4    >   ARRAY_KEY_EXISTS                                     ~4      !2, !1
          5        BOOL_NOT                                             ~5      ~4
          6      > JMPZ                                                         ~5, ->9
    7     7    >   FE_FREE                                                      $3
          8      > RETURN                                                       null
   11     9    >   FETCH_DIM_W                                          $6      !1, !2
         10        ASSIGN_REF                                                   !1, $6
    4    11      > JMP                                                          ->3
         12    >   FE_FREE                                                      $3
   14    13      > RETURN                                                       !1
   15    14*     > RETURN                                                       null

End of function findinarray

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.42 ms | 1918 KiB | 15 Q