First thing: Can someone please explain why it loses the $keys (i.e 101 becomes 0, 102 becomes 1...)??
Arrays are 0 indexed meaning they start with 0 not 1 to sort the use you can use the command sort
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
other commands that can be used with arrays:
* arsort() - Sort an array in reverse order and maintain index association
* asort() - Sort an array and maintain index association
* ksort() - Sort an array by key
* rsort() - Sort an array in reverse order
* usort() - Sort an array by values using a user-defined comparison function
* uksort() - Sort an array by keys using a user-defined comparison function
* array_multisort() - Sort multiple or multi-dimensional arrays
* krsort() - Sort an array by key in reverse order
* natsort() - Sort an array using a "natural order" algorithm
* natcasesort() - Sort an array using a case insensitive "natural order" algorithm
have a look at the php manual:
http://uk3.php.net/sort