PHP简单的冒泡排序法(。•ˇ‸ˇ•。)
程序员文章站
2022-05-27 10:00:22
...
php代码
<?php $b = [5,2,7,3,1,6,8,0]; // $b = [8,7,6,5,4,3,2,1,0];#直观地看出需要复循环几遍 $n = count($b); for($s = 0;$s < $n;$s++){ for($i = 0;$i $b[$i+1]) { #升序排序 $tmp = $b[$i+1]; $b[$i+1] = $b[$i]; $b[$i] = $tmp; } } } print_r($b);