October 2005
Intermediate to advanced
372 pages
11h 35m
English
arsort()
bool arsort ( array&arr[, intoptions] )
The arsort() function takes an array as its only parameter, and reverse sorts it by its values while preserving the keys. This is the opposite of the asort()
. For example:
$capitalcities['England'] = 'London';
$capitalcities['Wales'] = 'Cardiff';
$capitalcities['Scotland'] = 'Edinburgh';
arsort($capitalcities);
// reverse-sorted by value, so London, Edinburgh, CardiffNote that arsort() 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.