$data []=array (' team ') ' = ' $item [' post_name '], ' name ' + $item [' name '], ' total ' = $total, ' total_point ' =>$ Total_pt, ' total_hd ' = $total _hd, ' Chousale ' and $ChouSale, ' chousale_pt ' = $ChouSale _pt, ' CHOUSALE_HD ' =>$ CHOUSALE_HD,); $data = Syssortarray ($data, ' total_point ', ' sort_desc ', ' sort_numeric '); function Syssortarray ($ Arraydata, $KeyName 1, $SortOrder 1 = "Sort_asc", $SortType 1 = "Sort_regular") {if (!is_array ($ArrayData)) {return $ Arraydata;} $ArgCount = Func_num_args (); for ($I = 1; $I < $ArgCount; $I + +) {$Arg = Func_get_arg ($I); if (!eregi ("SORT", $Arg)) {$ Keynamelist[] = $ARG; $SortRule [] = ' $ '. $Arg;} else{$SortRule [] = $Arg;}} foreach ($ArrayData as $Key = $Info) {foreach ($KeyNameList as $KeyName) {${$KeyName}[$Key] = $Info [$KeyName];}} $EvalString = ' Array_multisort ('. Join (",", $SortRule). ', $ArrayData); eval ($EvalString); return $ArrayData;}
Sort using PHP's own Array_multisort function
$data = Array (); $data [] = Array (' volume ' = +, ' edition ' = 2); $data [] = Array (' volume ' = +, ' edition ' = 1); $data [] = Array (' volume ' = =, ' edition ' = 6); $data [] = Array (' volume ' = = 98, ' edition ' = 2); $data [] = Array (' volume ' = +, ' edition ' = 6); $data [] = Array (' volume ' = +, ' edition ' = 7); Get the list of columns foreach ($data as $key + = $row) { $volume [$key] = $row [' volume ']; $edition [$key] = $row [' edition ']; } Array_multisort ($volume, Sort_desc, $edition, SORT_ASC, $data); Print_r ($data);
Custom Function Sort 1
$data = Array (); $data [] = Array (' volume ' = +, ' edition ' = 2); $data [] = Array (' volume ' = +, ' edition ' = 1); $data [] = Array (' volume ' = =, ' edition ' = 6); $data [] = Array (' volume ' = = 98, ' edition ' = 2); $data [] = Array (' volume ' = +, ' edition ' = 6); $data [] = Array (' volume ' = +, ' edition ' = 7); Get the list of columns foreach ($data as $key + = $row) {$volume [$key] = $row [' volume ']; $edition [$key] = $row [' Edition ']; } $ret = ArraySort ($data, ' volume ', ' desc '); Print_r ($ret); /** * @desc arraysort php Two-dimensional array sort sorted by the specified key * @param array $arr will be sorted * @param string $keys Specify the sorted key * @param string $type sort type ASC | DESC * @return Array */function ArraySort ($arr, $keys, $type = ' asc ') {$keysvalue = $new _array = array (); foreach ($arr as $k = + $v) {$keysvalue [$k] = $v [$keys]; } $type = = ' ASC '? Asort ($keysvalue): Arsort ($KEYSVAlue); Reset ($keysvalue); foreach ($keysvalue as $k = + $v) {$new _array[$k] = $arr [$k]; } return $new _array; }
PHP Array sorting function