electricshoe Posted October 12, 2007 Share Posted October 12, 2007 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 More sharing options...
kenrbnsn Posted October 12, 2007 Share Posted October 12, 2007 Look at the function array_splice() Here's an example: <?php $ary = array(0,1,2,3,4); array_splice($ary,3,0,array('value1','value2','value3')); echo '<pre>' . print_r($ary,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/72979-solved-insert-into-middle-of-array/#findComment-368033 Share on other sites More sharing options...
electricshoe Posted October 12, 2007 Author Share Posted October 12, 2007 Derp, thank you very much! ;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 https://forums.phpfreaks.com/topic/72979-solved-insert-into-middle-of-array/#findComment-368113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.