Skip to content

Instantly share code, notes, and snippets.

@DevWellington
Created September 22, 2018 00:33
Show Gist options
  • Save DevWellington/4de83cc256fb40639ab9501928fe5b81 to your computer and use it in GitHub Desktop.
Save DevWellington/4de83cc256fb40639ab9501928fe5b81 to your computer and use it in GitHub Desktop.
Bubble Sort method with php
<?php
$list = [5,3,2,4,7,1,0,6];
print_r($list);
for ($i=0; $i < count($list); $i++) {
for ($j=$i+1; $j < count($list); $j++) {
$current = $list[$i];
$next = $list[$j];
if ($current > $next){
$list[$i] = $next;
$list[$j] = $current;
}
print_r("current: $current - next: $next" . PHP_EOL);
}
}
print_r($list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment