3v4l.org

run code in 300+ PHP versions simultaneously
<?php class test { public static function repeatedCharCount($string) { $lcString = strtolower($string); $prevChar = $lcString[0]; $currentLen = 0; $maxLen = 0; for ($i = 1; $i < strlen($lcString); $i++) { if ($lcString[$i] === $prevChar) { $currentLen += 1; } else { $currentLen = 1; } $maxLen = max($maxLen, $currentLen); $prevChar = $lcString[$i]; } return $maxLen; } public static function consecutiveCharCount($string) { $lcString = strtolower($string); $prevChar = $lcString[0]; $currentLen = 0; $maxLen = 0; $ascending = null; for ($i = 1; $i < strlen($lcString); $i++) { $diff = ord($lcString[$i]) - ord($prevChar); if ($diff == 1) { if ($ascending !== true) { $ascending = true; $currentLen = 1; } $currentLen += 1; } elseif ($diff == -1) { if ($ascending !== false) { $ascending = false; $currentLen = 1; } $currentLen += 1; } else { $currentLen = 1; } $maxLen = max($maxLen, $currentLen); $prevChar = $lcString[$i]; } return $maxLen; } } echo test::consecutiveCharCount("abcdegionoas"); echo test::consecutiveCharCount("EDCb00808asabc"); echo test::consecutiveCharCount("asg7898"); echo test::consecutiveCharCount("asgab876567asfon"); echo test::repeatedCharCount("abcdegionoas"); echo test::repeatedCharCount("EDCb00808asabc"); echo test::repeatedCharCount("asg7898"); echo test::repeatedCharCount("asgaaaCCc656bBBb7asfon");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vKeQp
function name:  (null)
number of ops:  33
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   INIT_STATIC_METHOD_CALL                                  'test', 'consecutiveCharCount'
          1        SEND_VAL                                                 'abcdegionoas'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   56     4        INIT_STATIC_METHOD_CALL                                  'test', 'consecutiveCharCount'
          5        SEND_VAL                                                 'EDCb00808asabc'
          6        DO_FCALL                                      0  $1      
          7        ECHO                                                     $1
   57     8        INIT_STATIC_METHOD_CALL                                  'test', 'consecutiveCharCount'
          9        SEND_VAL                                                 'asg7898'
         10        DO_FCALL                                      0  $2      
         11        ECHO                                                     $2
   58    12        INIT_STATIC_METHOD_CALL                                  'test', 'consecutiveCharCount'
         13        SEND_VAL                                                 'asgab876567asfon'
         14        DO_FCALL                                      0  $3      
         15        ECHO                                                     $3
   59    16        INIT_STATIC_METHOD_CALL                                  'test', 'repeatedCharCount'
         17        SEND_VAL                                                 'abcdegionoas'
         18        DO_FCALL                                      0  $4      
         19        ECHO                                                     $4
   60    20        INIT_STATIC_METHOD_CALL                                  'test', 'repeatedCharCount'
         21        SEND_VAL                                                 'EDCb00808asabc'
         22        DO_FCALL                                      0  $5      
         23        ECHO                                                     $5
   61    24        INIT_STATIC_METHOD_CALL                                  'test', 'repeatedCharCount'
         25        SEND_VAL                                                 'asg7898'
         26        DO_FCALL                                      0  $6      
         27        ECHO                                                     $6
   62    28        INIT_STATIC_METHOD_CALL                                  'test', 'repeatedCharCount'
         29        SEND_VAL                                                 'asgaaaCCc656bBBb7asfon'
         30        DO_FCALL                                      0  $7      
         31        ECHO                                                     $7
         32      > RETURN                                                   1

Class test:
Function repeatedcharcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 11
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 11
Branch analysis from position: 28
Branch analysis from position: 11
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 11
Branch analysis from position: 28
Branch analysis from position: 11
filename:       /in/vKeQp
function name:  repeatedCharCount
number of ops:  30
compiled vars:  !0 = $string, !1 = $lcString, !2 = $prevChar, !3 = $currentLen, !4 = $maxLen, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'strtolower'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
    7     5        FETCH_DIM_R                                      ~8      !1, 0
          6        ASSIGN                                                   !2, ~8
    8     7        ASSIGN                                                   !3, 0
    9     8        ASSIGN                                                   !4, 0
   10     9        ASSIGN                                                   !5, 1
         10      > JMP                                                      ->25
   11    11    >   FETCH_DIM_R                                      ~13     !1, !5
         12        IS_IDENTICAL                                             !2, ~13
         13      > JMPZ                                                     ~14, ->16
   12    14    >   ASSIGN_OP                                     1          !3, 1
         15      > JMP                                                      ->17
   14    16    >   ASSIGN                                                   !3, 1
   16    17    >   INIT_FCALL                                               'max'
         18        SEND_VAR                                                 !4
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $17     
         21        ASSIGN                                                   !4, $17
   17    22        FETCH_DIM_R                                      ~19     !1, !5
         23        ASSIGN                                                   !2, ~19
   10    24        PRE_INC                                                  !5
         25    >   STRLEN                                           ~22     !1
         26        IS_SMALLER                                               !5, ~22
         27      > JMPNZ                                                    ~23, ->11
   20    28    > > RETURN                                                   !4
   21    29*     > RETURN                                                   null

End of function repeatedcharcount

Function consecutivecharcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 12
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 12
Branch analysis from position: 49
Branch analysis from position: 12
Branch analysis from position: 27
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 35
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 12
Branch analysis from position: 49
Branch analysis from position: 12
filename:       /in/vKeQp
function name:  consecutiveCharCount
number of ops:  51
compiled vars:  !0 = $string, !1 = $lcString, !2 = $prevChar, !3 = $currentLen, !4 = $maxLen, !5 = $ascending, !6 = $i, !7 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'strtolower'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
   26     5        FETCH_DIM_R                                      ~10     !1, 0
          6        ASSIGN                                                   !2, ~10
   27     7        ASSIGN                                                   !3, 0
   28     8        ASSIGN                                                   !4, 0
   29     9        ASSIGN                                                   !5, null
   30    10        ASSIGN                                                   !6, 1
         11      > JMP                                                      ->46
   31    12    >   INIT_FCALL                                               'ord'
         13        FETCH_DIM_R                                      ~16     !1, !6
         14        SEND_VAL                                                 ~16
         15        DO_ICALL                                         $17     
         16        INIT_FCALL                                               'ord'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $18     
         19        SUB                                              ~19     $17, $18
         20        ASSIGN                                                   !7, ~19
   32    21        IS_EQUAL                                                 !7, 1
         22      > JMPZ                                                     ~21, ->29
   33    23    >   TYPE_CHECK                                  1014          !5
         24      > JMPZ                                                     ~22, ->27
   34    25    >   ASSIGN                                                   !5, <true>
   35    26        ASSIGN                                                   !3, 1
   37    27    >   ASSIGN_OP                                     1          !3, 1
         28      > JMP                                                      ->38
   38    29    >   IS_EQUAL                                                 !7, -1
         30      > JMPZ                                                     ~26, ->37
   39    31    >   TYPE_CHECK                                  1018          !5
         32      > JMPZ                                                     ~27, ->35
   40    33    >   ASSIGN                                                   !5, <false>
   41    34        ASSIGN                                                   !3, 1
   43    35    >   ASSIGN_OP                                     1          !3, 1
         36      > JMP                                                      ->38
   45    37    >   ASSIGN                                                   !3, 1
   47    38    >   INIT_FCALL                                               'max'
         39        SEND_VAR                                                 !4
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                         $32     
         42        ASSIGN                                                   !4, $32
   48    43        FETCH_DIM_R                                      ~34     !1, !6
         44        ASSIGN                                                   !2, ~34
   30    45        PRE_INC                                                  !6
         46    >   STRLEN                                           ~37     !1
         47        IS_SMALLER                                               !6, ~37
         48      > JMPNZ                                                    ~38, ->12
   51    49    > > RETURN                                                   !4
   52    50*     > RETURN                                                   null

End of function consecutivecharcount

End of class test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.11 ms | 1408 KiB | 19 Q