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 Quote 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 Quote 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. Quote 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. Quote 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. Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.