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) { foreach ($haystack as $value) { if (is_array($value)) { if (in_array($needle, $value)) { return true; } else { if (array_find($needle, $value)) { return true; } } } else { if ($value == $needle) { return true; } } } return false; } $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/gsCu3
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>
   28     1        ASSIGN                                                   !1, <array>
   30     2      > FE_RESET_R                                       $5      !1, ->15
          3    > > FE_FETCH_R                                               $5, !2, ->15
   31     4    >   INIT_FCALL                                               'array_find'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $6      
          8      > JMPZ                                                     $6, ->12
   32     9    >   ECHO                                                     !2
         10        ECHO                                                     '+found%0A'
         11      > JMP                                                      ->14
   34    12    >   ECHO                                                     !2
         13        ECHO                                                     '+not+found%0A'
   30    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $5
   36    16      > RETURN                                                   1

Function array_find:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 27
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/gsCu3
function name:  array_find
number of ops:  30
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2      > FE_RESET_R                                       $3      !1, ->27
          3    > > FE_FETCH_R                                               $3, !2, ->27
   11     4    >   TYPE_CHECK                                  128          !2
          5      > JMPZ                                                     ~4, ->22
   12     6    >   INIT_FCALL                                               'in_array'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $5      
         10      > JMPZ                                                     $5, ->14
   13    11    >   FE_FREE                                                  $3
         12      > RETURN                                                   <true>
         13*       JMP                                                      ->21
   15    14    >   INIT_FCALL_BY_NAME                                       'array_find'
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $6      
         18      > JMPZ                                                     $6, ->21
   16    19    >   FE_FREE                                                  $3
         20      > RETURN                                                   <true>
         21    > > JMP                                                      ->26
   20    22    >   IS_EQUAL                                                 !2, !0
         23      > JMPZ                                                     ~7, ->26
   21    24    >   FE_FREE                                                  $3
         25      > RETURN                                                   <true>
   10    26    > > JMP                                                      ->3
         27    >   FE_FREE                                                  $3
   25    28      > RETURN                                                   <false>
   26    29*     > RETURN                                                   null

End of function array_find

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.52 ms | 1403 KiB | 16 Q