The bubble sort and selection sort of php simple sort

Source: Internet
Author: User
 $arr [$j]) {$temp = $arr [$i];                $arr [$i] = $arr [$j];            $arr [$j] = $temp; }}} return $arr;}   /** * Select sort sort selectsort key is to find the smallest array subscript *///$arr = Array (100,2,4,5,6,1,7,3); Array (1,2,4,5,6,100,7,3) the first time//array (1,2,4,5,6,100,7,3) The second time//array (1,2,3,5,6,100,7,4) The third time//array ( 1,2,3,4,6,100,7,5) Fourth times//...//array (1,2,3,4,5,6,7,100) Last function Fn_selectsort ($arr) {for ($i = 0; $i < count ($ar R);        $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 minimum array subscript has been found, replace the current array with the smallest array found to replace if ($min! = $i) {$            temp = $arr [$i];            $arr [$i] = $arr [$min];        $arr [$min] = $temp; }} return $arr;}? >

By:19 Material

The above describes the simple sort of php bubble sorting and selection of sorting, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.