AI智能
改变未来

php冒泡排序

php冒泡排序

<?phpfunction sortNum($num){$numLenth=count($num);for ($i=1;$i<$numLenth;$i++){for ($j=0;$j<$numLenth-$i;$j++){if ($num[$j+1]<$num[$j]){$numJ1=$num[$j+1];$num[$j+1]=$num[$j];$num[$j]=$numJ1;}}}return $num;}$arr=Array(5,8,10,9,7);var_dump(sortNum($arr));//`在这里插入代码片`array (size=5)0 => int 51 => int 72 => int 83 => int 94 => int 10
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » php冒泡排序