arsort in PHP

Syntax of arsort

bool arsort(array array[, int flags])

Sorts an array in reverse order, maintaining the keys for the array values. The optional second parameter contains additional sorting flags. Returns true on success, false on failure

Example of arsort

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

Leave a Comment