Simple example of a function using a bubble sort method written in PHP, php bubble sort function _ PHP Tutorial

Source: Internet
Author: User
A simple example of a function using a bubble sort method written in PHP, and a php bubble sort function. A simple example of a function using a bubble sorting method written in PHP. a question about the algorithm encountered by the php bubble sorting function a few days ago requires that an array be sorted using the PHP language, A simple example of a bubble sort function I wrote in PHP, and a bubble sort function in php.

A question about algorithms that I encountered a few days ago asked me to sort an array using the PHP language. I wrote a function using the bubble sort method to share with you.

<? // Bubble sort 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); print_r ($ s);?>

The simple example of a bubble sort function written in PHP above is all the content shared by the editor. I hope you can give us a reference and support the help house.

I have encountered a question about algorithms a few days ago. I want to use PHP to sort an array...

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.