Just a suggestion how about the function sort?
$fruits = array ("lemon", "orange", "banana", "apple");
sort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key -> $val\n";
}
result is
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
there are others function also like ksort, asort, usort..etc