Skip to content

Instantly share code, notes, and snippets.

@antoniopicone
Created August 23, 2016 16:04
Show Gist options
  • Save antoniopicone/65984e71864954b26ce0d07c4b6898e7 to your computer and use it in GitHub Desktop.
Save antoniopicone/65984e71864954b26ce0d07c4b6898e7 to your computer and use it in GitHub Desktop.
A simple PHP implementation of the worst Bubble Sort
<?php
function bubbleSort($array) {
for($i=0;$i<sizeof($array);$i++) {
for($j=0;$j<sizeof($array)-1;$j++) {
if($array[$j]>$array[$j+1]) {
$temp = $array[$j];
$array[$j] = $array[$j+1];
$array[$j+1] = $temp;
}
}
}
return $array;
}
$arr = array(3,5,1,2,8,7,6,9,4);
echo implode(',', bubbleSort($arr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment