一、顺序查找
```
$arr = array(1,3,6,8,26,65,85);
//从数组第一个元素开始,挨个匹配
function check_order($arr,$num){
//全匹配
for($i=0;$len = count($arr);$i<$len;$i++){
if($arr[$i] == $num){
return $i;
}
}
return false;
}
```
二、二分查找
```
//此方法针对索引数组并且value为从小到大进行排序
$arr = array(1,3,6,8,26,65,85);
function check_break($arr,$res){
$right = count($arr);
$left = 0;
while($left <= $right){
$middle = floor(($right + $left) /2);
if($arr[$middle] == $res){
return $middle + 1;
}
if($arr[$middle] < $res){
$left = $middle + 1;
}else{
$right = $middle - 1;
}
}
return false;
}
```