3v4l.org

run code in 300+ PHP versions simultaneously
<?php $big = ['html', 'body', 'div', 'body','table', 'tbody', 'tr', 'td']; $small = ['body', 'div', 'td']; $wrong = ['td', 'body', 'div']; function isSubsequence($haystack,$needle){ if(count($needle) > count($haystack)) return false; $keys = array_keys($needle); $ptr = 0; $len = count($needle); foreach($haystack as $element){ if($ptr === $len) return true; if($needle[$keys[$ptr]] === $element) $ptr++; } return $ptr === $len; } var_dump(isSubsequence($big, $small)); var_dump(isSubsequence($big, $wrong));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vqBMj
function name:  (null)
number of ops:  18
compiled vars:  !0 = $big, !1 = $small, !2 = $wrong
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
   23     3        INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'issubsequence'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $6      
          8        SEND_VAR                                                 $6
          9        DO_ICALL                                                 
   24    10        INIT_FCALL                                               'var_dump'
         11        INIT_FCALL                                               'issubsequence'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !2
         14        DO_FCALL                                      0  $8      
         15        SEND_VAR                                                 $8
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

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

End of function issubsequence

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.32 ms | 1010 KiB | 17 Q