Skip to content

Instantly share code, notes, and snippets.

@shoyan
Created September 2, 2013 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoyan/6408294 to your computer and use it in GitHub Desktop.
Save shoyan/6408294 to your computer and use it in GitHub Desktop.
バブルソートで配列の値を昇順にソートする
<?php
/*
* バブルソートで配列の値を昇順にソートする
*
*/
$list = array(8, 1, 3, 4, 9, 5);
for ($j = 1; $j < count($list);$j++) {
for ($i = $j; $i < count($list); $i++) {
if ($list[$i - 1] > $list[$i]) {
$tmp = $list[$i];
$list[$i] = $list[$i - 1];
$list[$i - 1] = $tmp;
}
}
}
var_dump($list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment