Jump to content

[SOLVED] Insert Into Middle of Array


electricshoe

Recommended Posts

I've read over all of the array functions at php.net.

 

The closest thing to what I'm looking for is array_push().

 

But I can't figure out how to use push to put data in at a specific point in the array, just the beginning.

 

I want to insert data in the middle of my arrays while preserving/pushing back all the values behind it:

 

array(0,1,2,3,4);

 

insert_into_array at 2(value1,value2,value3)

 

so then my array is

 

0,1,2,value1,value2,value3,3,4

 

How do you do this? I'm feeling befuddled, maybe I should get more sleep (I really don't get enough sleep:()

 

Thanks for your help in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/72979-solved-insert-into-middle-of-array/
Share on other sites

Derp, thank you very much! ;D ;D ;D I forgot that setting zero on splice inserted the value.

 

Unfortunately I wound up setting it up a different way since the way I was including it broke the arrays relation to their dynamic variable children:(

 

But it works, and thank you very much for the info, hats off to you!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.