Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

PHPize.online is a free online environment for quickly running, experimenting with and sharing PHP (including Carbon extension for DateTime) and SQL code. You can run your SQL code with PHP code that can use the same DB. For database manipulations you can use pre-defined instances of PDO ($pdo), mysqli ($mysqli) & Laravel query builder ($db)

Copy Format Clear
Copy Clear
Copy Format Clear
<?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); print_r($start); } //наполяем массив символами строки начиная с первого символа: массив[буква] = индекс $array[$string[$end]] = $end; //сравнение максимальной длины: уже записанной $maxLength с $maxLength = max($maxLength, $end - $start + 1); //переходим на следующую букву до когца строки $end++; //print_r($end); } return $maxLength; } $t = getLongestLength('jabjcdel'); //print_r($t);
Show:  
Copy Clear