$ar = array("1","2","6","4","4");
function bubble1($ar){
$len = count($ar);
if($len > 1){
for($i = 0;$i < $len;$i++){
for($j = $len -1;$j > $i;$j-- ){
if($ar[$j-1] > $ar[$j] ){
$tmp = $ar[$j];
$ar[$j] = $ar[$j-1];
$ar[$j-1] = $tmp;
}
}
}
}
return($ar);
}
var_dump(bubble1($ar));
php的变量必须加$,打印语句有很多,如:echo,print,print_r等,我比较喜欢var_dump.