3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Run { public static function indexOfLongestRun($str) { echo strlen($str); $longest = array( 'pos' => 0, 'char' => NULL, 'run' => 0 ); $prev = NULL; $c_run = 0; foreach (str_split($str) as $pos => $char) { $c_run++; if (is_null($prev)) { $prev = $char; $longest['char'] = $char; } if ($prev != $char) { if ($c_run > $longest['run']) { $longest['char'] = $char; $longest['run'] = $c_run; $longest['pos'] = $pos - $c_run; } $c_run = 0; } $prev = $char; } return $longest['pos']; } } echo Run::indexOfLongestRun('abbcccddddcccbba');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eFWKb
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_STATIC_METHOD_CALL                                  'Run', 'indexOfLongestRun'
          1        SEND_VAL                                                 'abbcccddddcccbba'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Class Run:
Function indexoflongestrun:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 33
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 33
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 31
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 30
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 30
Branch analysis from position: 31
Branch analysis from position: 18
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/eFWKb
function name:  indexOfLongestRun
number of ops:  37
compiled vars:  !0 = $str, !1 = $longest, !2 = $prev, !3 = $c_run, !4 = $char, !5 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        STRLEN                                           ~6      !0
          2        ECHO                                                     ~6
    7     3        ASSIGN                                                   !1, <array>
   12     4        ASSIGN                                                   !2, null
   13     5        ASSIGN                                                   !3, 0
   14     6        INIT_FCALL                                               'str_split'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $10     
          9      > FE_RESET_R                                       $11     $10, ->33
         10    > > FE_FETCH_R                                       ~12     $11, !4, ->33
         11    >   ASSIGN                                                   !5, ~12
   15    12        PRE_INC                                                  !3
   16    13        TYPE_CHECK                                    2          !2
         14      > JMPZ                                                     ~15, ->18
   17    15    >   ASSIGN                                                   !2, !4
   18    16        ASSIGN_DIM                                               !1, 'char'
         17        OP_DATA                                                  !4
   20    18    >   IS_NOT_EQUAL                                             !2, !4
         19      > JMPZ                                                     ~18, ->31
   21    20    >   FETCH_DIM_R                                      ~19     !1, 'run'
         21        IS_SMALLER                                               ~19, !3
         22      > JMPZ                                                     ~20, ->30
   22    23    >   ASSIGN_DIM                                               !1, 'char'
         24        OP_DATA                                                  !4
   23    25        ASSIGN_DIM                                               !1, 'run'
         26        OP_DATA                                                  !3
   24    27        SUB                                              ~24     !5, !3
         28        ASSIGN_DIM                                               !1, 'pos'
         29        OP_DATA                                                  ~24
   26    30    >   ASSIGN                                                   !3, 0
   28    31    >   ASSIGN                                                   !2, !4
   14    32      > JMP                                                      ->10
         33    >   FE_FREE                                                  $11
   30    34        FETCH_DIM_R                                      ~27     !1, 'pos'
         35      > RETURN                                                   ~27
   31    36*     > RETURN                                                   null

End of function indexoflongestrun

End of class Run.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.7 ms | 1405 KiB | 15 Q