krsort
bool krsort(array array, [int flag])
|
array
|
Array to be sorted
|
|
flag
|
Flag specifying how to compare key values (PHP 4.0.0+ only)
|
Sorts an array in descending order by key.
Returns:
TRUE on success; NULL on failure
Description:
This function sorts array
in descending order by key. array
is directly modified. (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 keys according to PHP's normal comparison rules. This is the default if flag
is not given.
|
|
SORT_NUMERIC
|
Compare element keys according to their numeric values.
|
|
SORT_STRING
|
Compare element keys according to their string values.
|
Version:
PHP 3 since 3.0.13, PHP 4 since 4.0b4
See also:
array_multisort()
arsort()
asort()
ksort()
natsort()
natcasesort()
rsort()
sort()
uasort()
uksort()
usort()
Example:
Sort an array in reverse order by key
$array = array(2 => 1, '3' => 2, 1 => 3, 4 => 4);
krsort($array);
print_r($array);
Output:
Array
(
[4] => 4
[3] => 2
[2] => 1
[1] => 3
)
|