asort
asort
Sort an array in ascending order and maintain index association
true **asort** array $array int $flags
Sorts in place in ascending 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");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
c = apple
b = banana
d = lemon
a = orange
The fruits have been sorted in alphabetical order, and the index associated with each element has been maintained.
sort``arsort