Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function getLongestLength($string) {
$lenght = strlen($string);
$maxLength = 0;
$start = 0;
$end = 0;
$array = [];
//перебор строки
while ($end < $lenght) {
//
// if (array_key_exists($string[$end], $array)) {
// $start = max($array[$string[$end]] + 1, $start);
// }
//наполяем массив символами строки начиная с первого символа: массив[буква] = индекс
$array[$string[$end]] = $end;
//сравнение максимальной длины: уже записанной $maxLength с
$maxLength = max($maxLength, $end - $start + 1);
//переходим на следующую букву до когца строки
$end++;
print_r($end);
}
return $maxLength;
}
$t = getLongestLength('jabjcdel');
//print_r($t);