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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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