denoteone Posted September 13, 2010 Share Posted September 13, 2010 I have an array $array_1 ARRAY( [0] => info 1 [1] => info 2 [2] => info 3 ) and I have another array $array_2 ARRAY( [0] =>thank you and welcome to what ever [1] =>the info you added * thanks for entering your info ) I want to loop though the first array and place the values into the [1] of the second array. But the tricky thing is I want it to insert were the * is. foreach ($array_1 as $key => $val) { //not sure about this insert into ($array_2[1],after *, $val); } any help would be awesome. Quote Link to comment https://forums.phpfreaks.com/topic/213262-insert-array-vales-into-sting-of-another-array/ Share on other sites More sharing options...
meltingpoint Posted September 13, 2010 Share Posted September 13, 2010 Do you want to insert them into the array for storage back into your DB or do you want to insert them into the array to be included in the out put message? Quote Link to comment https://forums.phpfreaks.com/topic/213262-insert-array-vales-into-sting-of-another-array/#findComment-1110474 Share on other sites More sharing options...
sasa Posted September 13, 2010 Share Posted September 13, 2010 try <?php $array1 = array('info 1', 'info 2', 'info 3'); $array2 = array('thank you and welcome to what ever', 'the info you added * thanks for entering your info'); foreach ($array1 as $val) $array2[1] = str_replace('*', "* ".$val, $array2[1]); print_r($array2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/213262-insert-array-vales-into-sting-of-another-array/#findComment-1110536 Share on other sites More sharing options...
denoteone Posted September 13, 2010 Author Share Posted September 13, 2010 Thanks for you help that worked perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/213262-insert-array-vales-into-sting-of-another-array/#findComment-1110545 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.