October 2005
Intermediate to advanced
372 pages
11h 35m
English
krsort()
bool krsort ( array&arr[, intoptions] )
The krsort() function takes an array as its only parameter, and reverse sorts it by its keys while preserving the values. This is the opposite of the ksort()
. For example:
$capitalcities['England'] = 'London';
$capitalcities['Wales'] = 'Cardiff';
$capitalcities['Scotland'] = 'Edinburgh';
krsort($capitalcities);
// reverse-sorted by key, so Wales, Scotland, then EnglandNote that krsort() works by reference, directly changing the value you pass in. The return value is either true or false, depending on whether the sorting was successful.
By default, the sort functions sort so that 2 comes before 10. You can change this using the second parameter—see the
ksort()
reference for how to do this.