function BaseBSearch($x, $t) { $l = 0; $u = $n - 1; $p = 0; $m = 0; while (true) { if ($l > $u) { $p = -1; break; } if ($x[$m] < $t) { $l = $m + 1; } else if ($x[$m] == $t) { $p = $m; break; } else if ($x[$m] > $t) { $u = $m - 1; } } return $p; }