3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findSubsequence($needle, $haystack, $offset=0) { $l=count($needle); for($i=$offset,$c=count($haystack); $i<$c; ++$i) { if($haystack[$i] === $needle[0]) { for($k=1; $k<$l; ++$k) { if($haystack[$i+$k] !== $needle[$k]) { continue 2; } } return true; } } return false; } var_dump( findSubsequence([2,4], [1,2,3,4]), findSubsequence([2,4], [1,2,4,3]) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dar6i
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'var_dump'
   19     1        INIT_FCALL                                               'findsubsequence'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
   20     6        INIT_FCALL                                               'findsubsequence'
          7        SEND_VAL                                                 <array>
          8        SEND_VAL                                                 <array>
          9        DO_FCALL                                      0  $1      
         10        SEND_VAR                                                 $1
         11        DO_ICALL                                                 
   21    12      > RETURN                                                   1

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

End of function findsubsequence

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.58 ms | 1403 KiB | 17 Q