tags:

views:

30

answers:

2

Hi,

I have an array as follows

Array ( [0] => application [1] => modules [2] => Ride [3] => externals [4] => images [5] => uploads [6] => profile [7] => 116 [8] => 13006678321287904362.jpg ) 

How can I insert an item to the existing array with out overwriting the existing element in specified index

Consider I would like to create as follows

Array ( [0] => application [1] => modules [2] => Ride [3] => externals [4] => images [5] => uploads [6] => profile [7] => 116 [8] => model [9] => 13006678321287904362.jpg ) 

Any help please

+1  A: 

You can use array_slice, array_push and array_merge, I don't know if a better solution does exist.

MatTheCat
@MatTheCat: I think you are right, he wants to insert new item in the middle of the array.
Sarfraz
A: 

To elucidate on array_splice:

array_splice($array, $position, 0, $insert);

Where $array is the current array, $position is where you want to add the new item and $insert is the item to add (can be a new array)

Ergo Summary