AikenDrum Posted January 24, 2011 Share Posted January 24, 2011 Hi there, I am using HTML forms to post values from a data entry page. When they arrive on the second page - I have to extract them from the POST array. This is fine, but I now have to merge them somehow. When I use print_r to view the POSTed data, I see: [namesUnem] => Array ( [0] => Brian [1] => Richard [2] => Sarah ) [commentsUnem] => Array ( [0] => Brian Comments here [1] => Richard Comments should be entered here [2] => Sarah's Comments were also entered here ) [namesHW] => Array ( [0] => Sally [1] => Kate [2] => William ) [commentsHW] => Array ( [0] => Sally Comments here [1] => Kate's Comments should be entered here [2] => William's' Comments were also entered here ) There are 2 more such arrays being POSTed. I would need to merge in order to see the following: [Name] => Brian [Comment] => Brian Comments here [Type] => namesUnem [Name] => Richard [Comment] => Richard Comments should be entered here [Type] => namesUnem [Name] => Sarah [Comment] => Sarah's Comments were also entered here [Type] => namesUnem [Name] => Sally [Comment] => Sally Comments here [Type] => namesHW [Name] => Kate [Comment] => Kate's Comments should be entered here [Type] => namesHW [Name] => William [Comment] => William's' Comments were also entered here [Type] => namesHW Any help greatly appreciated Kindest Regards AikenD Quote Link to comment https://forums.phpfreaks.com/topic/225548-merging-3-arrays/ Share on other sites More sharing options...
bh Posted January 24, 2011 Share Posted January 24, 2011 array_combine Quote Link to comment https://forums.phpfreaks.com/topic/225548-merging-3-arrays/#findComment-1164611 Share on other sites More sharing options...
AikenDrum Posted January 24, 2011 Author Share Posted January 24, 2011 Hi there, many thanks indeed for the speedy reply - it's almpst there but not quite right. When I use combine, it uses the first array as the key, and does not allow for a 3rd or 4th array to be added. This is what it returns: Array ( [brian] => Brian Comments here [Richard] => Richard Comments should be entered here [sarah] => Sarah's Comments were also entered here ) This is the code I used: $nameUnemPost = (isset($_POST['nameUnem']))? $_POST['nameUnem'] : ""; $commentUnemPost = (isset($_POST['commentUnem']))? $_POST['commentUnem'] : ""; $combined = array_combine($nameUnemPost, $commentUnemPost); Any ideas as to the next step? Many thanks indeed AikenD Quote Link to comment https://forums.phpfreaks.com/topic/225548-merging-3-arrays/#findComment-1164670 Share on other sites More sharing options...
codefossa Posted January 24, 2011 Share Posted January 24, 2011 array_merge($array1, $array2, $array3); Quote Link to comment https://forums.phpfreaks.com/topic/225548-merging-3-arrays/#findComment-1164672 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.