3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findInArray($query, $data) { foreach ($query as $key) { if (!array_key_exists($key, $data)) { // The key was not found, set data to null and abort $data = null; break; } // Set data to the next level $data =& $data[$key]; } return $data; } $response = [ 'client1' => [ 'dog' => [ 'Jack' => 'Some value', 'Jack1' => 'Some value1', 'Jack2' => [ 'name' => 'Yes!', 'working' => [ 0 => 'Nope...', 1 => 'Seems like it!' ], ], ], ], 'client2' => [ 'cat' => [ 'Stacy' => 'Some other value', ], ], ]; $query = ['dog', 'Jack2', 'working', 1]; var_dump(findInArray($query, $response['client1']));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m4seY
function name:  (null)
number of ops:  11
compiled vars:  !0 = $response, !1 = $query
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                   !0, <array>
   41     1        ASSIGN                                                   !1, <array>
   43     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'findinarray'
          4        SEND_VAR                                                 !1
          5        FETCH_DIM_R                                      ~4      !0, 'client1'
          6        SEND_VAL                                                 ~4
          7        DO_FCALL                                      0  $5      
          8        SEND_VAR                                                 $5
          9        DO_ICALL                                                 
         10      > 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 = 42) Position 1 = 12
Branch analysis from position: 12
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
Branch analysis from position: 12
filename:       /in/m4seY
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    >   ASSIGN                                                   !1, null
    8     8      > JMP                                                      ->12
   12     9    >   FETCH_DIM_W                                      $7      !1, !2
         10        ASSIGN_REF                                               !1, $7
    4    11      > JMP                                                      ->3
         12    >   FE_FREE                                                  $3
   15    13      > RETURN                                                   !1
   16    14*     > RETURN                                                   null

End of function findinarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.56 ms | 1013 KiB | 15 Q