Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2011 20:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/898739 to your computer and use it in GitHub Desktop.
php recursive selection sort
<?php
function selection_sort ($array, $start=0, $current=0) {
if ($current == count($array)) { return $array; }
elseif ($start != $current && $array[$start] > $array[$current]) {
$temp = $array[$start];
$array[$start] = $array[$current];
$array[$current] = $temp;
}
return selection_sort(selection_sort($array, $start, $current+1), $start+1, $current=$start+1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment