升序
// 方法1
$a = [2, 4, 3, 1, 7, 5];
$c = count($a);
for ($i = 0; $i < $c - 1; $i++) {
for ($j = $i + 1; $j < $c; $j++) {
if ($a[$i] > $a[$j]) {
$t = $a[$i];
$a[$i] = $a[$j];
$a[$j] = $t;
}
}
}
print_r($a);
// 方法2
$a = [2, 4, 3, 1, 7, 5];
$c = count($a);
for ($i = 1; $i < $c; $i++) {
for ($j = 0; $j < $c - $i; $j++) {
if ($a[$j] > $a[$j + 1]) {
$t = $a[$j];
$a[$j] = $a[$j + 1];
$a[$j + 1] = $t;
}
}
}
print_r($a);