Is it possible to sort an array without changing the STARTING key? If so, how?
I have an array that starts with key 1 (I need it to start with key 1) but as expected, when I sort the array, the starting key becomes 0.
Example code below:
<?php
$array = array(
1 => 'string1',
2 => 'string2',
3 => 'string3',
);
print_r($array); //Outputs 'Array ( [1] => string1 [2] => string2 [3] => string3 )'
sort($array);
print_r($array); //Outputs 'Array ( [0] => string1 [1] => string2 [2] => string3 )'
?>
So with this example, I need $array
to start with key [1]
after sort()
.
asort()
is not an option, as I need the array to be in numerical order (again, starting from 1).
Could anyone help?