function Search($arr, $n, $v)
{
$left = 0;
$right = $n - 1; //6
while ($left <= $right){
$middle = bcdiv(bcadd($right, $left), 2);
if ($arr[$middle] > $v) {
$right = $middle - 1;
} elseif ($arr[$middle] < $v) {
$left = $middle + 1;
} else {
return $middle;
}
}
return -1;
}
{
$left = 0;
$right = $n - 1; //6
while ($left <= $right){
$middle = bcdiv(bcadd($right, $left), 2);
if ($arr[$middle] > $v) {
$right = $middle - 1;
} elseif ($arr[$middle] < $v) {
$left = $middle + 1;
} else {
return $middle;
}
}
return -1;
}