PHP bubble sorting

Source: Internet
Author: User
: This article mainly introduces the bubble sorting of PHP. if you are interested in the PHP Tutorial, refer to it. When I went to the cool dog interview yesterday, I had to use PHP to implement the bubble sorting programming question at the level of the test. because it was too long to use the bubble sorting, I forgot the algorithm principle, the result is left blank and it is speechless. So let's record the PHP bubble sorting code today:


  $ Numbers [$ j + 1]): ($ numbers [$ j] <$ numbers [$ j + 1]); if ($ swap) {$ temp = $ numbers [$ j + 1]; $ numbers [$ j + 1] = $ numbers [$ j]; $ numbers [$ j] = $ temp ;}} return $ numbers ;}$ arr = [1, 3, 5, 8, 4]; var_dump (bubble_sort ($ arr);/*** output: * array (size = 5) * 0 => int 1*1 => int 3*2 => int 4*3 => int 5*4 => int 8 */var_dump (bubble_sort ($ arr, false);/*** output: * array (size = 5) * 0 => int 8*1 => int 5*2 => int 4*3 => int 3*4 => int 1 */

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the bubble sorting of PHP, including some content, and hope to help friends who are interested in PHP tutorials.

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.