冒泡排序
//冒泡排序
class sort{
public function bubble_sort($array){
$count = count($array);
if($count<=0){
return false;
}
for($i = 0;$i<$count;$i++){
for($k = $count-1;$k>$i;$k--){
if($array[$k]<$array[$k-1]){
$tmp = $array[$k];
$array[$k] = $array[$k-1];
$array[$k-1] = $tmp;
}
}
}
return $array;
}
}
$sort = new sort;
$array = array(2,1,6,5,9,8);
$s = $sort->bubble_sort($sort);
var_dump($s);
滴水穿石