This example describes the PHP custom function to implement two-dimensional array sorting. Share to everyone for your reference, specific as follows:
/** function: Two-dimensional array sorting function, support multiple key name ordering * Return: Sort Good array * use: Array_msort (array, need to sort the key name, sort the way);
* Example: Array_msort ($cflist, "Chapter_orderid", "SORT_ASC");
* Array_msort ($arr, "name", "Sort_asc", "type", "Sort_desc", "size", "Sort_asc", "sort_string"); */function Array_msort ($ArrayData, $KeyName 1, $SortOrder 1 = "Sort_asc", $SortType 1 = "Sort_regular") {if (!is_array ($
Arraydata)) {return $ArrayData;
}//Get the number of parameters.
$ArgCount = Func_num_args ();
Sorted and placed into the Sortrule array for ($i = 1; $i < $ArgCount; $i + +) {$Arg = Func_get_arg ($i);
if (!eregi ("SORT", $Arg)) {$KeyNameList [] = $ARG;
$SortRule [] = ' $ '. $Arg;
else {$SortRule [] = $ARG;
}//Get the ' values according to the ' keys and put them to array. foreach ($ArrayData as $Key => $Info) {foreach ($KeyNameList as $KeyName) {${$KeyName}[$Key] = $Info [$KeyName
];
}//Create the eval string and eval it.
$EvalString = ' Array_multisort ('. Join (",", $SortRule). ', $ArrayData); '; eval ($EvalString);
return $ArrayData;
}
More about PHP Interested readers can view the site topics: "PHP array" Operation tips Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Mathematical Calculation Skills Summary, "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.