3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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');
based on A1Y6p
Output for 5.3.19 - 7.2.0
166