二分查找试用于有序数组
function select($arr, $m, $left, $right){
$mid = ceil(($left + $right) / 2);
//判断找不到的条件
if($mid >= $right){
die('找不到');
}
if($arr[$mid] === $m){
echo '找到了' . $mid;
}elseif($arr[$mid] > $m){
select($arr, $m, $left, $mid);
}else{
select($arr, $m, $mid, $right);
}
}
$arr = [1, 2, 3, 4, 5, 6];
select($arr, 4, 0, 4);