PHP » Arrays » krsort()

Syntax:
bool ksort (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 by key.

krsort() works like ksort(), but sorts in descending order.The elements are ordered by key, rather than value of the elements. 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:
<body>

<pre>
<?php

$cities = array(
   "Miami" => "Florida",
   "New Orleans" => "Louisiana",
   "Los Angeles" => "California",
   "Atlanta" => "Georgia",
   "Memphis" => "Tennessee");

krsort($cities);
print_r($cities);

?>
</pre>
Output:
Array
(
   [New Orleans] => Louisiana
   [Miami] => Florida
   [Memphis] => Tennessee
   [Los Angeles] => California
   [Atlanta] => Georgia
)
Explanation:

An array with cities as keys and states as values is sorted with krsort().

See Also: