//冒泡排序法 $arr = array(3,55,45,2,67,76,6.7,-65,85,4); function bubblingSort($arr){ for ( $i=0; $i<count($arr);$i++ ){ $flag = true; for ($j=0;$j<(count($arr)-1);$j++){ if ( $arr[$j]>=$arr[$j+1] ){ $transit_variable = $arr[$j]; $arr[$j] = $arr[$j+1]; $arr[$j+1] = $transit_variable; $flag = false; } } if ($flag){ return $arr; break; } } return $arr; } $res = bubblingSort($arr); echo "<pre>";print_r($res);