3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = array( 'A', 'B' => array('BA'), 'C' => array('CA' => array('CAA')), 'D' => array('DA' => array('DAA' => array('DAAA'))) ); function array_find($needle, array $haystack) { $found = false; $search = array('needle' => $needle, 'found' => &$found); array_walk_recursive($haystack, function($val, $key, $found) { if ($found['needle'] == $val) $found['found'] = true; }, $search); return $found;} $find = array('A', 'BA', 'CAA', 'DAAA'); foreach($find as $needle) { if (array_find($needle, $haystack)) { echo $needle, " found".PHP_EOL; } else { echo $needle, " not found".PHP_EOL; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/639Cu
function name:  (null)
number of ops:  17
compiled vars:  !0 = $haystack, !1 = $find, !2 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   19     2      > FE_RESET_R                                       $5      !1, ->15
          3    > > FE_FETCH_R                                               $5, !2, ->15
   20     4    >   INIT_FCALL                                               'array_find'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $6      
          8      > JMPZ                                                     $6, ->12
   21     9    >   ECHO                                                     !2
         10        ECHO                                                     '+found%0A'
         11      > JMP                                                      ->14
   23    12    >   ECHO                                                     !2
         13        ECHO                                                     '+not+found%0A'
   19    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $5
   25    16      > RETURN                                                   1

Function array_find:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/639Cu
function name:  array_find
number of ops:  14
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $found, !3 = $search
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN                                                   !2, <false>
   11     3        INIT_ARRAY                                       ~5      !0, 'needle'
          4        ADD_ARRAY_ELEMENT                                ~5      !2, 'found'
          5        ASSIGN                                                   !3, ~5
   12     6        INIT_FCALL                                               'array_walk_recursive'
          7        SEND_REF                                                 !1
          8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F639Cu%3A12%240'
   14     9        SEND_VAL                                                 ~7
         10        SEND_VAR                                                 !3
         11        DO_ICALL                                                 
   15    12      > RETURN                                                   !2
         13*     > RETURN                                                   null

End of function array_find

Function %00%7Bclosure%7D%2Fin%2F639Cu%3A12%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/639Cu
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $val, !1 = $key, !2 = $found
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   13     3        FETCH_DIM_R                                      ~3      !2, 'needle'
          4        IS_EQUAL                                                 !0, ~3
          5      > JMPZ                                                     ~4, ->8
          6    >   ASSIGN_DIM                                               !2, 'found'
          7        OP_DATA                                                  <true>
   14     8    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F639Cu%3A12%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.31 ms | 1407 KiB | 16 Q