二維數(shù)組排序算法與一維數(shù)組排序算法基本理論都是一樣,都是通過比較把小的值放在左變的數(shù)組里,大的值放在右邊的數(shù)組里在分別遞歸。
?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));