public function strrev($str) {
$rev_str = '';
if ($str == '') {
return 0;
}
for ($i = (strlen($str) - 1); $i >= 0; $i --) {
$rev_str .= $str[$i];
}
return $rev_str;
}
public function test() {
$arr = 'hellow wolrd';
var_dump($arr);
echo '<br/>';
$arr = $this->strrev($arr);
var_dump($arr);
}


//线性表删除
public function delete_array_element($array, $i) {
$len = count($array);
for ($j = $i; $j < $len; $j ++) {
if (isset($array[$j + 1])) {
$array[$j] = $array[$j + 1];
}
}
array_pop($array);
return $array;
}
public function test() {
$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
var_dump($arr);
echo '<br/>';
$arr = $this->delete_array_element($arr, 4);
var_dump($arr);
}


//二分查找法
public function bin_search($arr, $low, $high, $k) {
if ($low <= $high) {
$mid = intval(($low + $high) / 2);
if ($arr[$mid] == $k) {
return $mid;
} else if ($k < $arr[$mid]) {
return $this->bin_search($arr, $low, $mid - 1, $k);
} else {
return $this->bin_search($arr, $mid + 1, $high, $k);
}
}
return -1;
}
public function test() {
$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
var_dump($arr);
echo '<br/>';
$arr = $this->bin_search($arr, 0, 8, 4);
var_dump($arr);
}