Sort an associative array in descending order, according to the value:
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
arsort($age);
?>
Try it Yourself »
The arsort() function sorts an associative array in descending order, according to the value.
Tip: Use the asort() function to sort an associative array in ascending order, according to the value.
Tip: Use the krsort() function to sort an associative array in descending order, according to the key.
arsort(
array, sorttype)
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
sorttype | Optional. Specifies how to compare the array elements/items. Possible values:
|
Return Value: | TRUE on success. FALSE on failure |
---|---|
PHP Version: | 4+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!