<?php
function er_search($arr,$var){
$leng = count($arr);
$start =0;
$end =$leng-1;
while( $start <$end){
$mid=(int)($start+$end)/2;
if($arr[$mid]==$var){
return $mid;
}elseif( $arr[$mid]>$var){
$end= $mid-1;
}else{
$start=$mid+1;
}
}
return -9999;
}
$arr = array(1,2,3,4,5,6,7,8,11,13,14,156,157,2424,11312,142342,213);
echo er_search($arr,14);
?>
function er_search($arr,$var){
$leng = count($arr);
$start =0;
$end =$leng-1;
while( $start <$end){
$mid=(int)($start+$end)/2;
if($arr[$mid]==$var){
return $mid;
}elseif( $arr[$mid]>$var){
$end= $mid-1;
}else{
$start=$mid+1;
}
}
return -9999;
}
$arr = array(1,2,3,4,5,6,7,8,11,13,14,156,157,2424,11312,142342,213);
echo er_search($arr,14);
?>