Skip to content

Instantly share code, notes, and snippets.

@ytkhs
Created January 19, 2015 15:33
Show Gist options
  • Select an option

  • Save ytkhs/1c89ab7279e84b6e5d89 to your computer and use it in GitHub Desktop.

Select an option

Save ytkhs/1c89ab7279e84b6e5d89 to your computer and use it in GitHub Desktop.
<?php
$in = [111, 45, 4534, 4, 2356, 66];
$ordered = false;
$len = count($in);
while(!$ordered) {
$ordered = true;
for($i=1; $i<$len; $i++) {
$a = $in[$i-1];
$b = $in[$i];
if($a > $b) {
$in[$i-1] = $b;
$in[$i] = $a;
$marked = $i;
$ordered = false;
}
}
$len = $marked;
}
var_dump($in);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment