名称:PHP算法冒泡排序
当前代码
<?php //PHP算法冒泡排序 function bubbleSort($arr) { for ($i = 0; $i < count($arr); $i++) { for ($j = 0; $j < $i + 1; $j++) { if ($arr[$j] < $arr[$j - 1]) { $temp = $arr[$j - 1]; $arr[$j - 1] = $arr[$j]; $arr[$j] = $temp; } } } return $arr; } $bubble_start_time = microtime(true); $bubble_sort = bubbleSort($arr); $bubble_end_time = microtime(true); $bubble_need_time = $bubble_end_time - $bubble_start_time; print_r("冒泡排序耗时:" . $bubble_need_time . "<br />");