如何增加数组中的键 - PHP? [重复]

This question already has an answer here:

Let's say that I have the following array :

Array ( [0] => Jonny Cash [1] => Robert Smith )

How can I increment the array key in order to get something like this:

Array ( [1] => Jonny Cash [2] => Robert Smith )

Thanks in advance!

</div>

Push a null on to the front of the array and then delete it:

array_unshift($list, null);
unset($list[0]);
$array = array(1 => 'Jonny Cash', 2 => 'Robert Smith');
print_r($array);

Output:

Array ( [1] => Jonny Cash [2] => Robert Smith )

If you just want to make an existing array have a 1-based index, just add a fake entry at 0 and remove it:

// Assuming $array = Array ( [0] => Jonny Cash [1] => Robert Smith );

array_unshift($array, "fake");
unset($array[0]);