Jump to content

Merging 3 arrays


AikenDrum

Recommended Posts

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

Link to comment
Share on other sites

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

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.