3v4l.org

run code in 300+ PHP versions simultaneously
<?php function countFoundSequences(string $needle, string $haystack): int { if (!$needle) { return 0; } $tally = 0; $need = substr($needle, 0, 1); foreach (str_split($haystack) as $i => $straw) { if ($need === $straw) { if ($need === $needle) { ++$tally; } else { $tally += countFoundSequences( substr($needle, 1), substr($haystack, $i + 1) ); } } } return $tally; } echo countFoundSequences('abc', 'abcababc');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CIt3i
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'countfoundsequences'
          1        SEND_VAL                                                 'abc'
          2        SEND_VAL                                                 'abcababc'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5      > RETURN                                                   1

Function countfoundsequences:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 39
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 39
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 38
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/CIt3i
function name:  countFoundSequences
number of ops:  44
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $tally, !3 = $need, !4 = $straw, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        BOOL_NOT                                         ~6      !0
          3      > JMPZ                                                     ~6, ->5
    6     4    > > RETURN                                                   0
    8     5    >   ASSIGN                                                   !2, 0
    9     6        INIT_FCALL                                               'substr'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 1
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !3, $8
   10    12        INIT_FCALL                                               'str_split'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $10     
         15      > FE_RESET_R                                       $11     $10, ->39
         16    > > FE_FETCH_R                                       ~12     $11, !4, ->39
         17    >   ASSIGN                                                   !5, ~12
   11    18        IS_IDENTICAL                                             !3, !4
         19      > JMPZ                                                     ~14, ->38
   12    20    >   IS_IDENTICAL                                             !3, !0
         21      > JMPZ                                                     ~15, ->24
   13    22    >   PRE_INC                                                  !2
   12    23      > JMP                                                      ->38
   15    24    >   INIT_FCALL_BY_NAME                                       'countFoundSequences'
   16    25        INIT_FCALL                                               'substr'
         26        SEND_VAR                                                 !0
         27        SEND_VAL                                                 1
         28        DO_ICALL                                         $17     
         29        SEND_VAR_NO_REF_EX                                       $17
   17    30        INIT_FCALL                                               'substr'
         31        SEND_VAR                                                 !1
         32        ADD                                              ~18     !5, 1
         33        SEND_VAL                                                 ~18
         34        DO_ICALL                                         $19     
         35        SEND_VAR_NO_REF_EX                                       $19
   15    36        DO_FCALL                                      0  $20     
   17    37        ASSIGN_OP                                     1          !2, $20
   10    38    > > JMP                                                      ->16
         39    >   FE_FREE                                                  $11
   22    40        VERIFY_RETURN_TYPE                                       !2
         41      > RETURN                                                   !2
   23    42*       VERIFY_RETURN_TYPE                                       
         43*     > RETURN                                                   null

End of function countfoundsequences

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.53 ms | 1018 KiB | 16 Q