Created
August 23, 2016 16:04
-
-
Save antoniopicone/65984e71864954b26ce0d07c4b6898e7 to your computer and use it in GitHub Desktop.
A simple PHP implementation of the worst Bubble Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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