We have talked about various PHP array sorting methods before. At the same time, PHP also provides a large number of data sorting functions, such as sort(), asort(), arsort(), etc. Let me introduce two-dimensional arrays to you. Method to sort by specified key value.
Specific examples
The code is as follows
|
Copy code | ||||||||
/*The two-dimensional array is sorted by the specified key value*/ function array_sort($array,$keys,$type='asc'){
return ''; }
return '';}if(!isset($type) || $type=='' || !in_array(strtolower($type),array('asc','desc'))){ return '';} $val[$keys] = str_replace(':','',$val[$keys]); reset($keysvalue); //Redirect the pointer to the first $keysvalue = array(); } | return $keysvalue;
The code is as follows | Copy code |
array_sort($a,'price'); php array sort function sort ( &$arr [,fruits] ) Sort the array from low to high and assign a new key name. Return bool bKjia.c0m rsort ( &$arr [,fruits] ) Reverse sort the array and assign new key names asort ( &$arr [,fruits] ) sorts the array, keeping the index unchanged arsort( &$arr [,fruits] ) sorts the array in reverse order and keeps the index unchanged ksort ( &$arr [,fruits] ) sorts the array by key name krsort( &$arr [,fruits] ) sorts the group numbers in reverse order by key name natsort( &$arr ) Performs ‘natural sorting’ on array key values, sorting by length, alphabet, etc. natcasesort( &$arr ) performs case-insensitive ‘natural ranking’ of arrays usort ( &$arr , cmp_function ) User-defined function sorts an array and rearranges key names uksort (&$arr, cmp_function) User-defined function sorts an array by key name uasort (&$arr, cmp_function) user-defined function sorts the array and keeps the index unchanged array_multisort( $arr , mixed) The second parameter is to change the sorting behavior based on the value SORT_REGULAR Normal comparison unit SORT_NUMERIC www.bKjia.c0m The unit is compared as a number SORT_STRING The unit is compared as a string SROT_LOCALE_STRING The unit is compared as a string according to the current local settings |