Home>Article>Backend Development> PHP learning implementation sorting + search example
This article mainly talks about the code examples of using PHP to implement sorting and search. It has certain reference value. Interested friends can learn about it. I hope it can inspire you.
$array[$j]){ $temp = $array[$i]; $array[$i] = $array[$j]; $array[$j] = $temp; } } } return $array; } /* * 二分查找 */ function erfen($array,$search,$low = 0,$hight = 100) { $midPostion = floor(($low + $hight)/2); $midData = $array[$midPostion]; if($midData == $search) { return $midPostion; } if($search < $midData) { $hight = $midPostion; if($hight == 0) { return false; } return erfen($array,$search,$low,$hight); }else{ $low = $midPostion + 1; if($low > $hight){ return false; } return erfen($array,$search,$low,$hight); } } /* * 100+99+98+.......1; */ function leijia($n) { if($n == 1){ return $n; } return $n + leijia($n-1); } $a= array(9,4,6,8,2,4,5,1); $b= maopao($a); $c = array(1,2,3,4,5,6,7,8,9); $k = 5; $d = erfen($c,$k,0,8); $sum = leijia(100); echo $sum;
Related tutorials:PHP video tutorial
The above is the detailed content of PHP learning implementation sorting + search example. For more information, please follow other related articles on the PHP Chinese website!