Php simple sorting-bubble sorting and selection sorting

Source: Internet
Author: User
: This article mainly introduces the bubble sorting and selection sorting of php simple sorting. For more information about PHP tutorials, see.
 $ Arr [$ j]) {$ temp = $ arr [$ I]; $ arr [$ I] = $ arr [$ j]; $ arr [$ j] = $ temp; }}return $ arr ;} /*** select sort selectsort the key is to find the smallest array subscript * // $ arr = array (, 2,); // array, 6,100, 6,100, 6,100) first time // array (,) second time // array) third time // array (1, 2, 3, 4, 6,100, 7, 5) Fourth Time //... // array (7,100,) function fn_selectsort ($ arr) {for ($ I = 0; $ I <count ($ arr ); $ I ++) {$ min = $ I; for ($ j = $ I + 1; $ j <count ($ arr); $ j ++) {if ($ arr [$ min]> $ arr [$ j]) {$ min = $ j; // Find the smallest array subscript} // if the smallest array subscript is found, replace the current array with the minimum array found. if ($ min! = $ I) {$ temp = $ arr [$ I]; $ arr [$ I] = $ arr [$ min]; $ arr [$ min] = $ temp;} return $ arr ;}?>

By: 19 materials

The above introduces the simple sorting of php bubble sorting and selection sorting, including the content, hope to be helpful to 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.