Array push as the first index PHP

前端 未结 3 982
太阳男子
太阳男子 2021-01-31 14:37

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

3条回答
  •  礼貌的吻别
    2021-01-31 15:09

    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...

提交回复
热议问题