3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrpos(array $haystack, array $needle) { $len1 = count($haystack); $len2 = count($needle); if ($len2 > $len1) { return false; } for ($i = 0; $i <= $len1 - $len2; $i++) { if ($haystack[$i] === $needle[0]) { for ($j = 1; $j < $len2; $j++) { if ($haystack[$i + $j] !== $needle[$j]) { continue 2; } } return $i; } } return false; } $needle = [2,4]; var_dump(arrpos([1,2,3,4], $needle)); var_dump(arrpos([1,2,4,3], $needle)); var_dump(arrpos([1,2,2,4,3], $needle)); var_dump(arrpos([1,2,3,4,5], [2,3,4,5]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KsmfL
function name:  (null)
number of ops:  30
compiled vars:  !0 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   28     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'arrpos'
          3        SEND_VAL                                                 <array>
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   29     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'arrpos'
         10        SEND_VAL                                                 <array>
         11        SEND_VAR                                                 !0
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
   30    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'arrpos'
         17        SEND_VAL                                                 <array>
         18        SEND_VAR                                                 !0
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
   31    22        INIT_FCALL                                               'var_dump'
         23        INIT_FCALL                                               'arrpos'
         24        SEND_VAL                                                 <array>
         25        SEND_VAL                                                 <array>
         26        DO_FCALL                                      0  $8      
         27        SEND_VAR                                                 $8
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Function arrpos:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 11
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 17
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 11
Branch analysis from position: 31
Branch analysis from position: 11
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 17
Branch analysis from position: 26
Branch analysis from position: 17
Branch analysis from position: 27
filename:       /in/KsmfL
function name:  arrpos
number of ops:  33
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $len1, !3 = $len2, !4 = $i, !5 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        COUNT                                            ~6      !0
          3        ASSIGN                                                   !2, ~6
    5     4        COUNT                                            ~8      !1
          5        ASSIGN                                                   !3, ~8
    7     6        IS_SMALLER                                               !2, !3
          7      > JMPZ                                                     ~10, ->9
    8     8    > > RETURN                                                   <false>
   11     9    >   ASSIGN                                                   !4, 0
         10      > JMP                                                      ->28
   12    11    >   FETCH_DIM_R                                      ~12     !0, !4
         12        FETCH_DIM_R                                      ~13     !1, 0
         13        IS_IDENTICAL                                             ~12, ~13
         14      > JMPZ                                                     ~14, ->27
   13    15    >   ASSIGN                                                   !5, 1
         16      > JMP                                                      ->24
   14    17    >   ADD                                              ~16     !4, !5
         18        FETCH_DIM_R                                      ~17     !0, ~16
         19        FETCH_DIM_R                                      ~18     !1, !5
         20        IS_NOT_IDENTICAL                                         ~17, ~18
         21      > JMPZ                                                     ~19, ->23
   15    22    > > JMP                                                      ->27
   13    23    >   PRE_INC                                                  !5
         24    >   IS_SMALLER                                               !5, !3
         25      > JMPNZ                                                    ~21, ->17
   19    26    > > RETURN                                                   !4
   11    27    >   PRE_INC                                                  !4
         28    >   SUB                                              ~23     !2, !3
         29        IS_SMALLER_OR_EQUAL                                      !4, ~23
         30      > JMPNZ                                                    ~24, ->11
   23    31    > > RETURN                                                   <false>
   24    32*     > RETURN                                                   null

End of function arrpos

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.82 ms | 1403 KiB | 19 Q