function Qsort ($arr) {
Determines whether an array or an empty
if (!is_array ($arr) | | empty ($ARR)) {
return Array ();
}
Get array length
$len = count ($arr);
Determine length <=1 return array
if ($len <= 1) {
return $arr;
}
Define Middle Left right button
$key [0] = $arr [0];
$left = Array ();
$right = Array ();
Circular subscript starting from 1
for ($i =1; $i < $len; $i + +) {
Judge
if ($arr [$i] < $key [0]) {
On the left
$left [] = $arr [$i];
}else{
Right
$right [] = $arr [$i];
}
}
Recursive invocation
$left = Qsort ($left);
$right = Qsort ($right);
Merges multiple arrays and returns
Return Array_merge ($left, $key, $right);
}
$arr = Array (1232,57,34,657543,21,76,43476321,476,52,76,5,-23);
$arr = Qsort ($arr);
Var_dump ($arr);
?>
The above describes the PHP fast sorting method, including the content, I hope that the PHP tutorial interested in a friend helpful.