Array push as the first index PHP [duplicate] Array push as the first index PHP [duplicate] arrays arrays

Array push as the first index PHP [duplicate]


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

array_unshift($array, "Choose City")

or you can do it manually


I think you are looking for array_unshift() - this adds an element to the beginning of the array, rather than the end, without overwriting any existing elements.

However, the array will now be indexed starting at 0...


If you know that Index 0 is not used you can simply assign it:

$array[0] = "Choose City";