function binary_search ($array, $item, $low, $high
{
if ($low==-1) $low = 0;
if ($high==-1) $high = count$array)-1;
if ($low > $high) {
// item not found
return -1;
}
// get the middle
$middle = floor(($low$high)/2);
if ( $array$middle] == $item ) {
// found it
return $middle
} elseif ($item < $array$middle]) {
// search left
return binary_search$array, $item, $low, $middle-1);
} else {
// search right
return binary_search$array, $item, $middle+1, $high);
}
}