Sorts an array in descending order preserving keys.
arsort() works as asort(), but sorts in descending instead of ascending order. The previous keys are not discarded. Instead, the elements are merely reordered. The optional sort_type parameter specifies whether the elements should be sorted as strings or numerically. If the array was sorted successfully, TRUE is returned.
<pre>
<?php
$names = array("Johnson", "Williams", "Smith", "Jones");
$array1 = array(
"strawberry" => "red",
"blueberry" => "blue",
"raspberry" => "red");
arsort($names);
arsort($array1);
print_r($names);
print "<br>";
print_r($array1);
?>
</pre>
Array
(
[1] => Williams
[2] => Smith
[3] => Jones
[0] => Johnson
)
Array
(
[strawberry] => red
[raspberry] => red
[blueberry] => blue
)
arsort() reorders the elements in an array in descending order and without changing the keys.