Jump to content

array_combine modification


jjfletch

Recommended Posts

When I print_r($_POST) to determine what's being posted from my form, I get this:

[code=php:0]
Array ( [name] => Array ( [0] => Joe [1] => [2] => [3] => [4] => [5] => ) [animal] => Array ( [0] => Dog  [1] => Cat [2] => [3] => [4] => [5] => ) [submit] => Validez )
[/code]

Then, I array_combine to (duh) combine the arrays, and I get this:

[code=php:0]Array ( [Joe] => Dog [] => )[/code]


I'd like to get this:

[code=php:0]Array ( [Joe] => Dog [] => Cat)
[/code]
Anyone know how I can accomplish this?
Link to comment
Share on other sites

the array_combine is doing what you asked of it, it is taking the keys from your name array and combinging it with the keys of the animals array, as you only have one element in your name array it will only combine it with one element from your animal array, the first one, which happens to be dog, so after all that it is doing exactly what it is meant to do....

if you wish all the elements from one array to be joined with all the elements of another array then you need:-

[code]

$result = array_merge($array1, $array2);

[/code]

will result, when you print_r it

[code]

Array ( [0] => Joe [1] => Dog [2] => Cat )

[/code]
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.