asort
Sort the array and maintain index relationships
asort()
function sorts the associative arrays according to key values.
Tip: Please use the arsort()
function to sort the associative arrays in descending order by key values.
Tip: Please use the ksort()
function to sort the associative arrays according to the key names.
Sort the associative array by key value:
<?php $age = array ( "Bill" => "60" , "Steve" => "56" , "Mark" => "31" ) ; asort ( $age ) ; ?>
Try it yourself
asort ( 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:
|
asort()
function sorts 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.