3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ "1" => [ "book" => "Harry Potter", "artist" => array("David", "Emma"), "country" => [ ["description" => "Wander"], ["description" => "Magic"] ] ], "2" => [ "book" => "Science book", "artist" => array("Artist 1", "Melanie Hudson"), "country" => [ ["description" => "Physics"], ["description" => "Albert Einstein"] ] ], "3" => [ "book" => "Bible", "artist" => array("Artist 1", "Pedro"), "country" => [ ["description" => "Love"], ["description" => "Respect"] ] ], ]; $result = []; // $result is container for matches - filled by reference $needle = 'Wander'; // the key we are looking for recurse($data, $needle, $result); function recurse($haystack = [], $needle = '', &$result) { foreach($haystack as $key => $value) { if(is_array($value)) { recurse($value, $needle, $result); } else { if(strpos($value, $needle) !== false) { $result[] = $value; // store match } } } } echo '<pre>'; var_dump($result); echo '</pre>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E6LT6
function name:  (null)
number of ops:  14
compiled vars:  !0 = $data, !1 = $result, !2 = $needle
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   30     1        ASSIGN                                                       !1, <array>
   31     2        ASSIGN                                                       !2, 'Wander'
   32     3        INIT_FCALL_BY_NAME                                           'recurse'
          4        SEND_VAR_EX                                                  !0
          5        SEND_VAR_EX                                                  !2
          6        SEND_VAR_EX                                                  !1
          7        DO_FCALL                                          0          
   46     8        ECHO                                                         '%3Cpre%3E'
          9        INIT_FCALL                                                   'var_dump'
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                                     
         12        ECHO                                                         '%3C%2Fpre%3E'
         13      > RETURN                                                       1

Function recurse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/E6LT6
function name:  recurse
number of ops:  22
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $result, !3 = $value, !4 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   35     3      > FE_RESET_R                                           $5      !0, ->20
          4    > > FE_FETCH_R                                           ~6      $5, !3, ->20
          5    >   ASSIGN                                                       !4, ~6
   36     6        TYPE_CHECK                                      128          !3
          7      > JMPZ                                                         ~8, ->14
   37     8    >   INIT_FCALL_BY_NAME                                           'recurse'
          9        SEND_VAR_EX                                                  !3
         10        SEND_VAR_EX                                                  !1
         11        SEND_VAR_EX                                                  !2
         12        DO_FCALL                                          0          
   36    13      > JMP                                                          ->19
   39    14    >   FRAMELESS_ICALL_2                strpos              ~10     !3, !1
         15        TYPE_CHECK                                      1018          ~10
         16      > JMPZ                                                         ~11, ->19
   40    17    >   ASSIGN_DIM                                                   !2
         18        OP_DATA                                                      !3
   35    19    > > JMP                                                          ->4
         20    >   FE_FREE                                                      $5
   44    21      > RETURN                                                       null

End of function recurse

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
208.86 ms | 2152 KiB | 16 Q