PHP.nl

arsort

arsort

Sort an array in descending order and maintain index association

true **arsort** array $array int $flags

Sorts in place in descending order, such that its keys maintain their correlation with the values they are associated with. array

This is used mainly when sorting associative arrays where the actual element order is significant.

arrayThe input array.

return.true.always

Voorbeeld: example

<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}
?>
a = orange
d = lemon
b = banana
c = apple

The fruits have been sorted in reverse alphabetical order, and the index associated with each element has been maintained.

sort``asort