PHP » Arrays » rsort()

Syntax:
bool rsort (array array [, int sort_type])
array
Array to be sorted
sort_type
Can be SORT_REGULAR, SORT_NUMERIC, or SORT_STRING.

Sorts an array in descending order.

The rsort() function sorts an array in descending order. Except for the ordering, rsort() works just like sort(). Any keys in the array will be lost. 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.

Examples

Code:
<?php

function elementPrint($value)
{
   print "$value ";
}

$array1 = array(34, 75, 23, 68, 54, 91, 24, 12);
$array2 = array("orange", "banana", "apple", "plum", "pear");

rsort($array1);
array_walk($array1, "elementPrint");
print "<br>";

rsort($array2);
array_walk($array2, "elementPrint");

?>
Output:
91 75 68 54 34 24 23 12
plum pear orange banana apple
Explanation:

A numeric and a string array are sorted in reverse order.

See Also: