The
asort() array function in PHP will sort all of the elements in an array in ascending order according to the values. The indexes will be preserved. This function returns a value of either "true" or "false" when it runs.
<?php
$myArray = array("e1" => "Bike", "e2" => "Car", "e3" => "Anchor");
// Numeric values - $myArray = array("e1" => 300, "e2" => 200, "e3" => 400);
asort($myArray);
foreach($myArray as $key => $value) {
echo "$key - $value <br />";
}
?>
e3 - Anchor
e1 - Bike
e2 - Car