Home > Article > Backend Development > Detailed introduction to php arsort array descending sorting
arsort sorts an array in descending order and maintains index relationships.
Basic syntax
bool arsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
This function sorts the array in descending order, and the index of the array remains associated with the unit. The
arsort function is mainly used to sort associative arrays where the order of units is important.
Parameter introduction:
Description
arsort() function reversely sorts the array and maintains the index relationship. Mainly used for sorting associative arrays where the order of cells is important.
The optional second parameter contains additional sorting flags.
Return Value
Returns TRUE on success, or FALSE on failure.
Example:
<?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