function bubble_sort($array) { $count = count($array); if ($count < 0) return false; for($i = 0; $i < $count; $i++){ for ($j = $count - 1; $j > $i; $j --){ if ($array[$j] < $array[$j-1]){ $tmp = $array[$j]; $array[$j] = $array[$j - 1]; $array[$j-1] = $tmp; } print_r($array); echo ""; } } return $array; } $arr = array(49, 38, 65, 97, 76, 13, 27); $arr = bubble_sort($arr); print_r($arr);