Skip to content

Instantly share code, notes, and snippets.

@DevWellington
Created September 22, 2018 10:41
Show Gist options
  • Save DevWellington/588aa3b75c8983fb4e18e74ef9134c12 to your computer and use it in GitHub Desktop.
Save DevWellington/588aa3b75c8983fb4e18e74ef9134c12 to your computer and use it in GitHub Desktop.
Selection Sort method with PHP
<?php
$list = [64,25,12,22,11];
print_r("list: ". implode(',',$list) . PHP_EOL);
for ($i=0; $i < count($list); $i++) {
$min = $i;
print_r($list[$i].PHP_EOL);
for ($j = $i + 1; $j < count($list); $j++) {
print_r("\t".$list[$j].PHP_EOL);
$current = $list[$min];
$next = $list[$j];
if ($next < $current){
$list[$min] = $next;
$list[$j] = $current;
}
print_r("\t\tlist: ". implode(',',$list) . PHP_EOL);
}
}
print_r("list: ". implode(',',$list) . PHP_EOL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment