Jump to content

Take keys and values out of an array and make a new one


clay1

Recommended Posts

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?

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.