快速排序
1 $arr=array(33,2,54,25,65,34,67,42,87,90,243,213,365,78,67,345,678); 2 3 function quick_sort($arr){ 4 $len = count($arr); 5 if($len <= 1) 6 { 7 return $arr; 8 } 9 $key = $arr[0]; 10 $arr_left = array(); 11 $arr_right = array(); 12 for ($i=1;$i<$len;$i++) 13 { 14 if($arr[$i] <= $key){ 15 $arr_left[] = $arr[$i]; 16 }else{ 17 $arr_right[] = $arr[$i]; 18 } 19 } 20 $arr_left = quick_sort($arr_left); 21 $arr_right = quick_sort($arr_right); 22 return array_merge($arr_left,array($key),$arr_right); 23 } 24 25 echo '<pre>'; 26 print_r(quick_sort($arr)); 27 echo '</pre>';