This is a irregular series (10%7 = 3, 11%7 = 4 —– 15%7=1)
3
4
5
6
0
1
What will be the next integer of this series using php?
Expected output 16%7 =2.
My try. It is considering 7. But I don’t want to consider 7
<?php
function findNextInSeries($series, $divisor) {
// Determine the last remainder
$lastValue = end($series);
$lastRemainder = $lastValue % $divisor;
// Find the next remainder in the sequence
$nextRemainder = ($lastRemainder + 1) % $divisor;
// Iterate to find the next number in the sequence
for ($i = $lastValue + 1; ; $i++) {
if ($i % $divisor == $nextRemainder) {
return $i;
}
}
}
// Given series
$series = [10, 11, 12, 13, 14, 15];
$divisor = 7;
// Find the next integer in the series
$nextValue = findNextInSeries($series, $divisor);
echo "The next integer in the series is: $nextValue";
?>