php冒泡排序

$b=array('4','3','8','9','2','1');
$len=count($b);//6
第一种:
for($k=0;$k<=$len;$k++)
{
    for($j=$len-1;$j>$k;$j--){
        if($b[$j]<$b[$j-1]){
            $temp = $b[$j];
            $b[$j] = $b[$j-1];
            $b[$j-1] = $temp;
        }
    }
}
第二种:
for($k=1;$k<$len;$k++)
{
    for($j=0;$j<$len-$k;$j++){
        if($b[$j]>$b[$j+1]){
            $temp =$b[$j+1];
            $b[$j+1] =$b[$j] ;
            $b[$j] = $temp;
        }
    }
}
原文地址:https://www.cnblogs.com/lxwphp/p/15454657.html