tags:

views:

50

answers:

3

Lets say I have this array:

$array = array(1,2,'b','c',5,6,7,8,9.10);

Later in the script, I want to add the value 'd' before 'c'. How can I do this?

+2  A: 

Use array_splice as following:

array_splice($array, 3, 0, array('d'));
Ivan Nevostruev
+2  A: 

See array_splice

mobrule
+1  A: 

or a more self-made approach: Loop array until you see 'd' insert 'c' then 'd' in the next one. Shift all other entries right by one

Vladimir