You can just divide the number by 1000
since you have a 1000 interval range in a consecutive way.
The quotient * 1000 + 1
is your start value for the interval with an exceptional corner case of a number divisible by 1000, which would just be the border end for an interval.
<?php
$tests = [1,999,1000,50001,100000,2999];
foreach($tests as $test_case){
$quotient = intval($test_case / 1000);
if($test_case % 1000 === 0){
$start = $test_case - 1000 + 1;
echo "$test_case : Range: ($start - $test_case)",PHP_EOL;
}else{
$start = $quotient * 1000 + 1;
$end = ($quotient + 1) * 1000;
echo "$test_case : Range: ($start - $end)",PHP_EOL;
}
}
Output:
1 : Range: (1 - 1000)
999 : Range: (1 - 1000)
1000 : Range: (1 - 1000)
50001 : Range: (50001 - 51000)
100000 : Range: (99001 - 100000)
2999 : Range: (2001 - 3000)
Demo: https://3v4l.org/apbqV