Welcome to the Linux community forum and interact with 2 million technical staff to enter the two-dimensional array Sorting Algorithm and one-dimensional array sorting algorithm. The basic theories are the same, we put small values in the left-changing array by comparison, and put large values in the right-side array for recursion respectively .? PhpclassBubble {privatefunction _ construct () {} pri
Welcome to the Linux community forum to interact with 2 million technical staff> the basic theories of the Two-dimensional array Sorting Algorithm and the one-dimensional array sorting algorithm are the same, by relatively placing small values in the left-changing array, the large values are placed in the right array and recursive respectively. ? Php class Bubble {private function _ construct () {} pri
Welcome to the Linux community forum and interact with 2 million technicians>
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.
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 ));