arsort
Reversely sort the array and maintain index relationships
arsort()
function sorts the associative arrays in descending order by key values.
Tip: Please use the asort()
function to sort the associative arrays in ascending order by key values.
Tip: Please use the krsort()
function to sort the associative arrays in descending order by key names.
Sort the associative arrays in descending order by key values:
<?php $age = array ( "Bill" => "60" , "Steve" => "56" , "Mark" => "31" ) ; arsort ( $age ) ; ?>
Try it yourself
arsort ( array , sortingtype ) ;
parameter | describe |
---|---|
array | Required. Specifies the array to be sorted. |
sortingtype |
Optional. Specifies how to arrange elements/items of an array. Possible values:
|
arsort()
function reverses the array and maintains the index relationship. It is mainly used to sort those combined arrays whose unit order is important.
The optional second parameter contains the additional sorting identifier.
Return TRUE if successful, otherwise return FALSE.