[Solved] how to find a sequence of 5 number which is the highest [closed]


First, you need to make a loop. The loop needs to execute a number of times equal to the length of the input string minus the length of the substring you want to evaluate. Calculate that length before constructing the loop.

$digits = 5;
$count = strlen($number) - $digits;

Then initialize a maximum value. Loop from zero to the count you calculated, and take substrings starting from the position indicated by your loop increment variable. Compare them to your previous maximum value and overwrite that value with the current substring if it is greater.

$max = 0;

for ($i = 0; $i <= $count; $i++) {
    $substr = substr($number, $i, $digits);
    $max = max($max, $substr);
}

solved how to find a sequence of 5 number which is the highest [closed]