//选择排序法 $arr = array(3,55,45,2,67,76,6.7,-65,85,4); function selectSort($arr){ for ( $i=0; $i<count($arr);$i++ ){ $index = $i; $min_val = $arr[$i]; for ($j=$i+1;$j<count($arr);$j++){ if ( $arr[$j]<=$min_val ){ $min_val = $arr[$j]; $index = $j; } } $arr[$index] = $arr[$i]; $arr[$i] = $min_val; } return $arr; } $res = selectSort($arr); echo "<pre>";print_r($res); exit;