PHP arsort () function
Examples
Associative arrays in descending order according to the key:
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
arsort($age);
?>
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
arsort($age);
?>
Running instance »
Definition and Usage
arsort () function in accordance with an associative array key in descending order.
Tip: Use asort () function in accordance with an associative array key in ascending order.
Tip: Use krsort () function for an associative array in accordance with the keys in descending order.
grammar
arsort( array,sortingtype );
参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
sortingtype | 可选。规定如何排列数组的元素/项目。可能的值:
|
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 4+ |
Complete PHP Array Reference