A simple example of a function with a bubbling Sort method written in PHP, PHP bubble sort function
A few days ago encountered a question about the algorithm, asked to use the PHP language implementation of an array to sort, I wrote a bubble sorting method of the function, and share with you.
<?//Bubble Sort Method 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;} $arr = Array (3, 5, 1, 4, 2); $s = Bubble_sort ($arr);p rint_r ($s);? >
The above this is written in PHP with a bubble sorting function Simple example is the small part to share all the content of everyone, I hope to give you a reference, but also hope that we support a lot of help the home.
http://www.bkjia.com/PHPjc/1133069.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133069.html techarticle A simple example of the function of a bubble sorting method written in PHP, the PHP bubble sorting function encountered a few days ago a question about the algorithm, the PHP language required to implement an array to sort, I ...