asort in PHP

Syntax of asort

bool asort(array array[, int flags])

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

Example of asort

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

Leave a Comment