Php two-dimensional array quick sorting algorithm implementation code, two-dimensional array algorithm

Source: Internet
Author: User

Php two-dimensional array quick sorting algorithm implementation code, two-dimensional array algorithm

Php two-dimensional array quick sorting algorithm implementation code

The basic theories of the Two-dimensional array Sorting Algorithm and the one-dimensional array sorting algorithm are the same. They both place small values in the left-changing array by comparison, and the large values in the right array by recursion respectively.

Instance code:

<?php class Bubble {   private function __construct() {   }   private static function sortt($data) {     if (count ( $data ) <= 1) {      return $data;     }     $tem = $data [0]['score'];     $leftarray = array ();     $rightarray = array ();     for($i = 1; $i < count ( $data ); $i ++) {       if ($data [$i]['score'] <= $tem ) {         $leftarray[] = $data[$i];       } else {         $rightarray[] = $data[$i];       }     }     $leftarray=self::sortt($leftarray);     $rightarray=self::sortt($rightarray);     $sortarray = array_merge ( $leftarray, array ($data[0]), $rightarray );     return $sortarray;   }   public static function main($data) {     $ardata = self::sortt ( $data );     return $ardata;   } }  $arr=array(   array('sid'=>1,'score'=>76),   array('sid'=>2,'score'=>93),   array('sid'=>3,'score'=>68.5),   array('sid'=>4,'score'=>82.5),   array('sid'=>5,'score'=>60.5) ); print_r(Bubble::main($arr)); 

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

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.