Summary of PHP sorting functions. Sort damages index ascending value sorting Rsort damages index descending value sorting Asort keeps index ascending value sorting Arsort keeps index descending value sorting Ksort keeps index ascending key value sorting Sort destroys index ascending sort values
Rsort destroys sorting of index values in descending order
Asort sort index values in ascending order
Arsort keeps the index sorted in descending order
Ksort keeps indexes sorted by key in ascending order)
Krsort keeps the index sorted by key in descending order)
Usort
This function uses a user-defined comparison function to sort the values in an array. If the array to be sorted needs to be sorted by an unusual standard, use this function.
A comparison function must return an integer less than, equal to, or greater than zero when the first parameter is considered to be less than, equal to, or greater than the second parameter.
Uksort
Uksort-sort the keys in the array using the user-defined comparison function
Cmp_functionThe function should accept two parameters, which will beArrayIn. When the first parameter is less than, equal to, or greater than the second parameter, the comparison function must return an integer less than zero, equal to zero, or greater than zero.
Natsort
This function implements a sorting algorithm that is the same as the method that people usually sort character strings and maintain the Association of original keys/values. this is called "natural sorting ". This algorithm and the general computer string sorting algorithm
Bool natcasesort (array & $ array)Case insensitive
This function implements a sorting algorithm that is the same as the method that people usually sort character strings and maintain the Association of original keys/values. this is called "natural sorting ".
Return if successfulTRUE, Or return when the failure occurs.FALSE.
For example, to sort two-dimensional arrays, use the built-in functions asort and arsort.
The idea is to keep the key values of $ keyvalue and $ arr the same, and then assign the column $ arr wants to sort to $ keyvalue, and use the built-in function to sort $ keyvalue,
Finally, other columns of $ arr are returned based on the unchanged key value.
Function array_sort ($ arr, $ keys, $ type = 'asc ')
{
Echo 'start sorting ...'.'
';
$ Keysvalue = $ new_array = array ();
Foreach ($ arr as $ k => $ v)
{
$ Keysvalue [$ k] = $ v [$ keys];
}
If ($ type = 'asc ')
{
}
Else
{
}
Reset ($ keysvalue );
Foreach ($ keysvalue as $ k => $ v)
{
$ New_array [$ k] = $ arr [$ k];
}
Echo 'sorting ends ...'.'
';
Return $ new_array;
}
Http://www.bkjia.com/PHPjc/750880.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/750880.htmlTechArticleSort damage index ascending sort Rsort damage index descending sort Asort keep Index ascending sort Arsort keep Index descending sort Ksort keep Index ascending sort key value...