lethalMango
lethalMango

Reputation: 4491

Add Data to 3 Dim Array

I have the following array containing a master record of training courses held on a system (select_group just identifies related course groups):

Array
(
    [DE00041-1] => Array
        (
            [select_group] => 1
        )
)

The training course ids are then queried against a table containing only running courses whilst also grabbing extra information.

As one training course may run more than once per year they have a running_id which gives the following:

Array
(
    [DE00041-1] => Array
        (
            [title] => xxx
            [405] => Array
                (
                    [start_quarter] => 1
                    [end_quarter] => 1
                )
        )
)

What I then need to do is add the original array select_group data into the newly created array.

The end result should be:

Array
(
    [DE00041-1] => Array
        (
            [title] => xxx
            [select_group] => 1
            [405] => Array
                (
                    [start_quarter] => 1
                    [end_quarter] => 1
                )
        )
)

I have looked over other SO / Google answers but couldn't find what I was looking for.

There may be 1-20 training courses listed, each one running once to four times per year.

Upvotes: 0

Views: 53

Answers (2)

dfsq
dfsq

Reputation: 193271

Another variant:

$result = array_merge_recursive($arr1, $arr2);

Upvotes: 0

worenga
worenga

Reputation: 5856

foreach($yourArray as $key => $value){
   $yourArray[$key]['select_group'] = $select_group_array[$key]['select_group'];
}

Upvotes: 3

Related Questions