I have an two arrays in php, what i would like to do is if drug_ids match, I want to add the second array as a sub array. What I have
Array
(
[0] => Array
(
[drug_id] => 1
[drug] => Abacavir 300mg - Tabs
)
[1] => Array
(
[drug_id] => 4
[drug] => Abacavir/Lamivudine 120/60mg - FDC Tabs
)
[2] => Array
(
[drug_id] => 3
[drug] => Abacavir/Lamivudine 600/300mg - FDC Tabs
)
);
The second array with more data
Array
(
[0] => Array
(
[id] => 2
[decision_date] => 2018-08-10
[discussion] => The product is at 2.6 MOS
[recommendation] => recommendation
[drug_id] => 1
[created] => 2018-08-16 09:23:09
[user] => System Admin
)
[1] => Array
(
[id] => 3
[decision_date] => 2018-08-10
[discussion] => recommendation.
[recommendation] =>recommendation.
[drug_id] => 4
[created] => 2018-08-16 09:23:09
[user] => System Admin
)
[2] => Array
(
[id] => 4
[decision_date] => 2018-08-10
[discussion] => The product is at 6MOS.
[recommendation] =>ggfgfg.
[drug_id] => 4
[created] => 2018-08-16 09:23:09
[user] => System Admin
)
);
I would like to push the second array into the first one as decisions if drug ids match to create a final array
[0] => Array
(
[drug_id] => 4
[drug] => Abacavir/Lamivudine 120/60mg - FDC Tabs
[decisions] => Array(
[0] => Array
(
[id] => 3
[decision_date] => 2018-08-10
[discussion] => recommendation.
[recommendation] =>recommendation.
[drug_id] => 4
[created] => 2018-08-16 09:23:09
[user] => System Admin
)
[1] => Array
(
[id] => 4
[decision_date] => 2018-08-10
[discussion] => The product is at 6MOS.
[recommendation] =>ggfgfg.
[drug_id] => 4
[created] => 2018-08-16 09:23:09
[user] => System Admin
)
)
)
Any suggestions as to how this can be achieved?
What i have tried $table_data //first array $table_data //second array
foreach ($table_data as $mt) {
foreach ($items as $it) {
if ($it['drug_id'] == $mt['drug_id']) {
$decision['decisions'] = $it;
array_push($table_data, $decision);
}
}
}
//This does not work
foreach()loops and matching the two sets of values together?