Array push as the first index PHP

Karem picture Karem · Dec 1, 2011 · Viewed 92.8k times · Source

I have an array that doesn't use the 0 index. The array starts from 1,2,3. So I would like to add to the array. I tried do array_push($array, "Choose City"), but this ends up at the end of the array, with array index 4 in this case.

How can I set it to be the array index 0?

Answer

JC Lee picture JC Lee · Dec 1, 2011

http://php.net/manual/en/function.array-unshift.php

array_unshift($array, "Choose City")

or you can do it manually