<?php /** * Created by PhpStorm. * User: huangye * Date: 2015/8/26 * Time: 18:57 */ //大数排在后边 function bubbleSort($a_data) { $len = count($a_data); for ($i = 0; $i < $len; $i++) { for ($j = 0; $j < $len - $i - 1; $j++) { if ($a_data[$j] > $a_data[$j + 1]) { $temp = $a_data[$j]; $a_data[$j] = $a_data[$j + 1]; $a_data[$j + 1] = $temp; } } } return $a_data; } $num = array(20, 40, 60, 80, 30, 70, 90, 10, 50, 0); var_dump(bubbleSort($num));
原文:http://www.cnblogs.com/huangye-dream/p/4991467.html