function direct_sort($data) { $count = count($data); if($count == 0) return; elseif($count == 1) return $data; for($i = 0; $i < $count; $i ++) { for ($j = $i + 1; $j < $count; $j ++) { if ($data[$i] > $data[$j]) { $temp = $data[$i]; $data[$i] = $data[$j]; $data[$j] = $temp; } } } return $data; } $array = array(8,2,9,1,3); print_r(bulle_sort($array)); ------------------------------------------- for($i = 0; $i < $count; $i ++) { for ($j = $count - 1; $j > $i; $j --){ if ($data[$j-1] > $data[$j]){ $temp = $data[$j-1]; $data[$j-1] = $data[$j]; $data[$j] = $temp; } } }