Php arsort array sort in descending order
Arsort sorts arrays in descending order and maintains the index relationship.
Basic syntax
Bool arsort (array & $ array [, int $ sort_flags = SORT_REGULAR])
This function sorts the array in descending order. The index of the array remains associated with the unit.
The arsort function is mainly used to sort the arrays that are very important to the unit order.
Parameter introduction:
Parameters |
Description |
Array |
Required. Input array. |
Sort_flags |
Optional. Specifies how to arrange the elements/items of an array. Possible values:
- 0 = SORT_REGULAR-default. Sort each item in the regular order (Standard ASCII, without changing the type)
- 1 = SORT_NUMERIC-process each item as a number.
- 2 = SORT_STRING-process each item as a string.
- 3 = SORT_LOCALE_STRING-process each item as a string based on the current region settings (which can be changed through setlocale ).
- 4 = SORT_NATURAL-process each item as a string and use natural sorting like natsort.
- 5 = SORT_FLAG_CASE-you can combine (by bit or) SORT_STRING or SORT_NATURAL to sort strings without case sensitivity.
|
Description
The arsort () function sorts arrays in reverse order and maintains the index relationship. It is mainly used to sort the arrays that are very important to the unit order.
The second optional parameter contains an additional sorting identifier.
Return Value
Returns TRUE if the call succeeds, or FALSE if the call fails.
Instance:
<?php$fruits = array( "d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");arsort($fruits);foreach ($fruits as $key => $val) { echo " $key = $val <br/>";}?>
Running result:
A = orange
D = lemon
B = banana
C = apple
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!