A simple example of the function of a bubbling Sort method written in PHP, php bubble sort function _php Tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.