- print_r: documentation ( source)
- sort: documentation ( source)
<?php
$numbers = array(1105,2140,3170,1000,1500,1501);
$start = 1000;
$end = 1500;
$start_index = -1;
sort($numbers);
$low = 0; $high = count($numbers) - 1;
while($low <= $high){
$mid = intval(($low + $high) / 2);
if($numbers[$mid] > $end){
$high = $mid - 1;
}else if($numbers[$mid] < $start){
$low = $mid + 1;
}else{
$start_index = $mid;
$high = $mid - 1;
}
}
$result = [];
for($i = $start_index; $i < count($numbers); ++$i){
if($numbers[$i] > $end) break;
$result[] = $numbers[$i];
}
print_r($result);