PHP asort()Functions
Complete PHP Array Reference Manual
Examples
Sort an associative array in ascending order according to its values:
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
asort($age);
?>
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
asort($age);
?>
Run Example »
Definition and Usage
The asort() function sorts an associative array in ascending order according to its values.
Tip:Please usearsort()to sort an associative array in descending order according to its values.
Tip:Please useksort()to sort an associative array in ascending order according to its keys.
Syntax
asort(array,sortingtype);
| Parameter | Description |
|---|---|
| array | Required. Specifies the array to be sorted. |
| sortingtype | Optional. Specifies how to arrange the elements/items of the array. Possible values:
|
Technical Details
| Return Value: | Returns TRUE on success, FALSE on failure. |
|---|---|
| PHP Version: | 4+ |
Other Extensions