sort(); changes key numbers of array
Hello!
I have a question about using function sort();
I set the initial key of array to be 1 (instead of default 0). Everything goes OK until I sort the array. After sorting the array initial key value sets itself back to zero.
Here is the example:
<?php
$var = array(1 => "Good", "Better", "The Best");
foreach ($var as $index => $value)
{
echo $index." - ".$value."<br />";
}
sort($var);
foreach ($var as $index => $value)
{
echo "<br />".$index." - ".$value;
}
?>
How to avoid the change of the initial array key?
The output should be:
1 - Better
2 - Good
3 - The Best
