clay1 Posted January 17, 2010 Share Posted January 17, 2010 Say I have my $_POST array Let's say I have 3 items- Name, Email, Comment I need to take name and email and make a new array with them let's call it User[] And then I need an array with just the comment. So I should end up with 2 separate arrays. Suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/188734-take-keys-and-values-out-of-an-array-and-make-a-new-one/ Share on other sites More sharing options...
Catfish Posted January 17, 2010 Share Posted January 17, 2010 Assuming there is only 1 value for a Name, Email and Comment: foreach ($_POST as $key => $value) { if($key == 'Name' || $key == 'Email') $personArray[$key] = $value; else $commentArray[$key] = $value; } print_r($personArray); print('<br/>'."\n"); print_r($commentArray); Quote Link to comment https://forums.phpfreaks.com/topic/188734-take-keys-and-values-out-of-an-array-and-make-a-new-one/#findComment-996293 Share on other sites More sharing options...
clay1 Posted January 17, 2010 Author Share Posted January 17, 2010 Thanks! I knew it would be something along those lines, but arrays and foreach make my brain spin Quote Link to comment https://forums.phpfreaks.com/topic/188734-take-keys-and-values-out-of-an-array-and-make-a-new-one/#findComment-996294 Share on other sites More sharing options...
clay1 Posted January 17, 2010 Author Share Posted January 17, 2010 Yeah there are only 1 value for each because I got rid of all the nested arrays from the checkboxes that were causing problems with this thing Quote Link to comment https://forums.phpfreaks.com/topic/188734-take-keys-and-values-out-of-an-array-and-make-a-new-one/#findComment-996295 Share on other sites More sharing options...
Catfish Posted January 17, 2010 Share Posted January 17, 2010 keep mucking around with them and one day it will click then you'll wonder how you did without them. Quote Link to comment https://forums.phpfreaks.com/topic/188734-take-keys-and-values-out-of-an-array-and-make-a-new-one/#findComment-996296 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.