Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sorting algorithm in PHP
function quickSort($array)
{
if (!$length = count($array)) {
return $array;
}
$k = $array[0];
$x = $y = array();
for ($i=1;$i<$length;$i++) {
if ($array[$i] <= $k) {
$x[] = $array[$i];
} else {
$y[] = $array[$i];
}
}
return array_merge(quickSort($x),array($k),quickSort($y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.