Sorts an array in ascending order preserving keys.
asort() sorts an array in ascending order, but unlike sort(), the previous keys are not discarded. The elements are merely reordered. The optional sort_type parameter specifies whether the elements should be sorted as strings or numerically. If the array was sorted successfully, TRUE is returned.
<pre>
<?php
$names = array("Johnson", "Williams", "Smith", "Jones");
$array1 = array(
"strawberry" => "red",
"blueberry" => "blue",
"raspberry" => "red");
asort($names);
asort($array1);
print_r($names);
print "<br>";
print_r($array1);
?>
</pre>
Array
(
[0] => Johnson
[3] => Jones
[2] => Smith
[1] => Williams
)
Array
(
[blueberry] => blue
[raspberry] => red
[strawberry] => red
)
asort() reorders the elements in an array without changing the keys.