PHP two-dimensional array sorting function, the default natural sort, or sort. Here you can specify a variety of methods to sort by a value in a two-dimensional array, depending on the program annotation below.
Copy Code code as follows:
/**
* @function natural ordering of two-dimensional arrays
* @author www.phpernote.com
* @param array $array arrays to be sorted (two-dimensional)
* @param string key needs to be sorted by which key
* @param string Ordering method (Sort_asc,sort_desc)
* @param String Type Sort method (sort_regular,sort_numeric,sort_string)
* @return Array sorted array.
*/
function Phpsortarray ($array, $key, $order = "Sort_asc", $type = "Sort_regular") {
if (!is_array ($array) | | Empty ($ $array)) {
return $array;
}
$ArgCount =func_num_args ()//returns the number of arguments passed to the currently defined function
for ($I =1; $I < $ArgCount; $I + +) {
$Arg =func_get_arg ($I);
if (!eregi ("SORT", $Arg)) {
$KeyNameList []= $Arg;
$SortRule []= ' $ '. $Arg;
}else{
$SortRule []= $Arg;
}
}
foreach ($array as $Key => $Info) {
foreach ($KeyNameList as $KeyName) {
${$KeyName}[$Key]= $Info [$KeyName];
}
}
$EvalString = ' Array_multisort ('. Join (",", $SortRule). ', $array); ';
eval ($EvalString);
return $array;
}