3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dictionary = array("hello", "hi", "how r u", "how are you", "how r you", "how are u"); function isDictionaryWord($str,$dictionary){ foreach($dictionary as $each_word){ if(isSubsequence(strtolower($each_word),strtolower($str))){ return true; } } return false; } function isSubsequence($needle,$haystack){ $len1 = strlen($needle); $len2 = strlen($haystack); if($len1 > $len2) return false; $ptr = 0; for($i=0;$i<$len2 && $ptr < $len1;$i++){ if($haystack[$i] === $needle[$ptr]) $ptr++; } return $ptr == $len1; } $tests = array( 'Hello', 'Helloooo', 'How r youuu !!!!', 'hell', 'w are y' ); foreach($tests as $each_test){ echo $each_test," => ",var_dump(isDictionaryWord($each_test,$dictionary)),PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/N2avQ
function name:  (null)
number of ops:  18
compiled vars:  !0 = $dictionary, !1 = $tests, !2 = $each_test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1        ASSIGN                                                   !1, <array>
   37     2      > FE_RESET_R                                       $5      !1, ->16
          3    > > FE_FETCH_R                                               $5, !2, ->16
   38     4    >   ECHO                                                     !2
          5        ECHO                                                     '+%3D%3E+'
          6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'isdictionaryword'
          8        SEND_VAR                                                 !2
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                         $7      
         13        ECHO                                                     $7
         14        ECHO                                                     '%0A'
   37    15      > JMP                                                      ->3
         16    >   FE_FREE                                                  $5
   39    17      > RETURN                                                   1

Function isdictionaryword:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/N2avQ
function name:  isDictionaryWord
number of ops:  21
compiled vars:  !0 = $str, !1 = $dictionary, !2 = $each_word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2      > FE_RESET_R                                       $3      !1, ->18
          3    > > FE_FETCH_R                                               $3, !2, ->18
    8     4    >   INIT_FCALL_BY_NAME                                       'isSubsequence'
          5        INIT_FCALL                                               'strtolower'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8        SEND_VAR_NO_REF_EX                                       $4
          9        INIT_FCALL                                               'strtolower'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12        SEND_VAR_NO_REF_EX                                       $5
         13        DO_FCALL                                      0  $6      
         14      > JMPZ                                                     $6, ->17
    9    15    >   FE_FREE                                                  $3
         16      > RETURN                                                   <true>
    7    17    > > JMP                                                      ->3
         18    >   FE_FREE                                                  $3
   12    19      > RETURN                                                   <false>
   13    20*     > RETURN                                                   null

End of function isdictionaryword

Function issubsequence:
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 = 18
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 12
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
Branch analysis from position: 22
Branch analysis from position: 17
Branch analysis from position: 22
filename:       /in/N2avQ
function name:  isSubsequence
number of ops:  26
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $len1, !3 = $len2, !4 = $ptr, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        STRLEN                                           ~6      !0
          3        ASSIGN                                                   !2, ~6
   17     4        STRLEN                                           ~8      !1
          5        ASSIGN                                                   !3, ~8
   18     6        IS_SMALLER                                               !3, !2
          7      > JMPZ                                                     ~10, ->9
          8    > > RETURN                                                   <false>
   19     9    >   ASSIGN                                                   !4, 0
   21    10        ASSIGN                                                   !5, 0
         11      > JMP                                                      ->18
   22    12    >   FETCH_DIM_R                                      ~13     !1, !5
         13        FETCH_DIM_R                                      ~14     !0, !4
         14        IS_IDENTICAL                                             ~13, ~14
         15      > JMPZ                                                     ~15, ->17
         16    >   PRE_INC                                                  !4
   21    17    >   PRE_INC                                                  !5
         18    >   IS_SMALLER                                       ~18     !5, !3
         19      > JMPZ_EX                                          ~18     ~18, ->22
         20    >   IS_SMALLER                                       ~19     !4, !2
         21        BOOL                                             ~18     ~19
         22    > > JMPNZ                                                    ~18, ->12
   25    23    >   IS_EQUAL                                         ~20     !4, !2
         24      > RETURN                                                   ~20
   26    25*     > RETURN                                                   null

End of function issubsequence

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.12 ms | 1010 KiB | 16 Q