经典PHP面试题(冒泡排序),当场就被打脸,卧槽什么冒泡?为啥还排序?
<?php //冒泡排序 $arr = [45,45,54,45,64,46,12,4,45,4,1,12,456,4,511,245,]; function maopao($arr){ $len = count($arr); for($k = 0;$k < $len;$k++){ for($j = $len-1;$j>$k;$j--){ if($arr[$j]<$arr[$j-1]){ $temp = $arr[$j]; $arr[$j] = $arr[$j-1]; $arr[$j-1]= $temp; } } } return $arr; } var_dump(maopao($arr));