Arsort an array in descending order and maintains an indexed relationship.
Basic syntax
BOOL Arsort (array & $array [, int $sort _flags = sort_regular])
This function is sorted in descending order, and the index of the array is persisted and the cell is associated.
The Arsort function is primarily used to sort the associative arrays that are important to the order of the cells.
Parameter introduction:
| Parameters |
Description |
| Array |
Necessary. The array entered. |
| Sort_flags |
Optional. An element/item that prescribes how an array is arranged. Possible values:
- 0 = sort_regular-default. Arrange each item in a regular order (Standard ASCII without changing the type)
- 1 = sort_numeric-Treat each item as a number.
- 2 = sort_string-handles each item as a string.
- 3 = sort_locale_string-handles each item as a string, based on the current locale (which can be changed by setlocale ()).
- 4 = sort_natural-handles each item as a string, using a natural sort similar to Natsort ().
- 5 = sort_flag_case-the string can be sorted in combination (bitwise OR) sort_string or sort_natural, case-insensitive.
|
Description
The Arsort () function reverses the array and maintains an indexed relationship. It is primarily used to sort the associative arrays that are important to the order of the cells.
The optional second parameter contains an additional sort identity.
return value
Returns TRUE on success or FALSE on failure.
Instance:
<?php
$fruits = Array (
"D" => "Lemon",
"a" => "orange",
"B" => "banana",
"C" => " Apple "
);
Arsort ($fruits);
foreach ($fruits as $key => $val) {
echo $key = $val <br/>;
}
? >
Run Result:
A = Orange
D = Lemon
b = Banana
c = Apple
Thank you for reading, I hope to help you, thank you for your support for this site!