kn0wl3dg3 Posted May 16, 2011 Share Posted May 16, 2011 I looked through all the array functions in the manual, but didn't see what I needed (might have just missed it) Is there a way to stick a value into the middle of an array, without writing over the current value? I would need it to just push the rest back 1. Hope that explains what Im looking for! Thanks in advance Link to comment https://forums.phpfreaks.com/topic/236574-insert-a-value-into-the-middle-of-an-array/ Share on other sites More sharing options...
kn0wl3dg3 Posted May 16, 2011 Author Share Posted May 16, 2011 I just realized I was in the mysql board when I posted this! SORRY!!! Can a mod please move it Link to comment https://forums.phpfreaks.com/topic/236574-insert-a-value-into-the-middle-of-an-array/#findComment-1216172 Share on other sites More sharing options...
jcbones Posted May 16, 2011 Share Posted May 16, 2011 There isn't a function to do that, but there are ways to do it. We would need to know the context of what is needed before even beginning. Like, what is in the array, how the arrangement is to be assigned, what is the expected output. Link to comment https://forums.phpfreaks.com/topic/236574-insert-a-value-into-the-middle-of-an-array/#findComment-1216246 Share on other sites More sharing options...
requinix Posted May 16, 2011 Share Posted May 16, 2011 There isn't a function to do that Actually there is. Use $length=0. Link to comment https://forums.phpfreaks.com/topic/236574-insert-a-value-into-the-middle-of-an-array/#findComment-1216250 Share on other sites More sharing options...
jcbones Posted May 17, 2011 Share Posted May 17, 2011 Ah, I missed that when I looked at array_splice. I would have worked up a very long winded, and complicated approach. Link to comment https://forums.phpfreaks.com/topic/236574-insert-a-value-into-the-middle-of-an-array/#findComment-1216295 Share on other sites More sharing options...
kn0wl3dg3 Posted May 17, 2011 Author Share Posted May 17, 2011 I knew there had to be something.. Ah, I missed that when I looked at array_splice. I did too. Thanks to both of you. Going to look into it and see what happens. Be back if I need more help. Thanks Link to comment https://forums.phpfreaks.com/topic/236574-insert-a-value-into-the-middle-of-an-array/#findComment-1216319 Share on other sites More sharing options...
kn0wl3dg3 Posted May 17, 2011 Author Share Posted May 17, 2011 That did the trick, thank you Link to comment https://forums.phpfreaks.com/topic/236574-insert-a-value-into-the-middle-of-an-array/#findComment-1216455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.