rsort
bool rsort(array array, [int flag])
|
array
|
Array to sort
|
|
flag
|
Flag specifying how to compare key values (PHP 4.0.0+ only)
|
Sorts an array in descending order by element value.
Returns:
TRUE on success; FALSE on failure
Description:
Sorts array
in descending order by element value. String indexes are ignored and the resulting array is indexed numerically. Use arsort() if you're working with an associative array. The key values for the resulting indexed array are reordered after the sort is completed.
array
is modified directly by this function.
(PHP 4.0.0+ only) The way in which element values are compared can be modified by passing one of the following named constants as flag
:
|
SORT_REGULAR
|
Compare element values according to PHP's normal comparison rules. This is the default if flag
is not given.
|
|
SORT_NUMERIC
|
Compare element values according to their numeric values.
|
|
SORT_STRING
|
Compare element values according to their string values.
|
Version:
PHP 3, PHP 4
See also:
array_multisort()
arsort()
asort()
krsort()
ksort()
natsort()
natcasesort()
sort()
uasort()
uksort()
usort()
Example:
Sort an array in descending order by element value
$array = array('b' => 2, 'd' => 4, 'a' => 1, 'c' => 3);
rsort($array);
print_r($array);
Output (note that string indexes have been lost):
Array
(
[0] => 4
[1] => 3
[2] => 2
[3] => 1
)
|