冒泡排序

156 阅读1分钟
<?php
$arr = [2,1,6,5,8];

function maopao($array)
{
    $count = count($array);
    for($i = 1;$i<$count;$i++)
    {
        for($j = 0;$j<$count-$i;$j++)
        {
            if($array[$j]>$array[$j+1])
            {
                $tem = $array[$j];
                $array[$j]= $array[$j+1];
                $array[$j+1] = $tem;
            }
        }
    }
    return $array;
}
$res = maopao($arr);
print_r($res);