//冒泡
$a = array(2,1,3,9,8,4,5);
$count = count($a);
for ($i=0; $i < $count; $i++) {
# code...
for ($j=0; $j < $count-1; $j++) {
# code...
if ($a[$j] > $a[$j+1]) {
$tmp = $a[$j+1];
$a[$j+1] = $a[$j];
$a[$j] = $tmp;
}
}
}
print_r($a);
网友评论