This article introduces the two-dimensional array sorting and default natural sorting methods in php. If you need a friend, refer to the php two-dimensional array sorting function. the default is natural sorting, that is, sort sorting. You can specify multiple methods to sort values by values in a two-dimensional array. For more information, see the program annotations below.
/*** @ Function: natural sorting of two-dimensional arrays * @ author www.phpernote.com * @ param array $ array the array to be sorted (two-dimensional) * @ param string key sort by which key * @ param string order (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 (); // return the number of parameters passed to the current 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 ;}
For more information about php two-dimensional array sorting and default natural sorting methods, refer to PHP!