Skip to content

Instantly share code, notes, and snippets.

@DanielKucal
Last active October 1, 2015 21:01
Show Gist options
  • Save DanielKucal/caa7bd91e5c01e050625 to your computer and use it in GitHub Desktop.
Save DanielKucal/caa7bd91e5c01e050625 to your computer and use it in GitHub Desktop.
function mySort(array $elements) {
$sorted = true;
for ($i = 0; $i < count($elements)-1; $i++) {
if ($elements[$i] > $elements[$i+1]) {
$tmp = $elements[$i+1];
$elements[$i+1] = $elements[$i];
$elements[$i] = $tmp;
$sorted = false;
}
}
if ($sorted) {
return $elements;
} else {
return mySort($elements);
}
}
print_r(mySort([3, 5, 1, 2, 8, 0]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment