3v4l.org

run code in 500+ PHP versions simultaneously
<?php $haystack = [0,0,0,1,1,0,1,1,0,0,1,1,0,0,1]; $needle = [1,1,0]; $needleCount = count($needle); $result = []; foreach ($haystack as $i => $straw) { $start = $i - $needleCount; if ( $start >= 0 && $needle === array_slice($haystack, $start, $needleCount) ) { $result[] = $straw; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 23
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 22
Branch analysis from position: 19
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/piUe9
function name:  (null)
number of ops:  28
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $needleCount, !3 = $result, !4 = $straw, !5 = $i, !6 = $start
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    4     1        ASSIGN                                                       !1, <array>
    6     2        COUNT                                                ~9      !1
          3        ASSIGN                                                       !2, ~9
    7     4        ASSIGN                                                       !3, <array>
    8     5      > FE_RESET_R                                           $12     !0, ->23
          6    > > FE_FETCH_R                                           ~13     $12, !4, ->23
          7    >   ASSIGN                                                       !5, ~13
    9     8        SUB                                                  ~15     !5, !2
          9        ASSIGN                                                       !6, ~15
   11    10        IS_SMALLER_OR_EQUAL                                  ~17     0, !6
         11      > JMPZ_EX                                              ~17     ~17, ->19
   12    12    >   INIT_FCALL                                                   'array_slice'
         13        SEND_VAR                                                     !0
         14        SEND_VAR                                                     !6
         15        SEND_VAR                                                     !2
         16        DO_ICALL                                             $18     
         17        IS_IDENTICAL                                         ~19     !1, $18
         18        BOOL                                                 ~17     ~19
         19    > > JMPZ                                                         ~17, ->22
   14    20    >   ASSIGN_DIM                                                   !3
         21        OP_DATA                                                      !4
    8    22    > > JMP                                                          ->6
         23    >   FE_FREE                                                      $12
   18    24        INIT_FCALL                                                   'var_export'
         25        SEND_VAR                                                     !3
         26        DO_ICALL                                                     
         27      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
191.61 ms | 1882 KiB | 15 Q