<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
The above example will output:
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.