This is my data:
$dataItems = [
[
'id' => 1,
'serial' => "XXXXXXAA1",
'pd_item_info' =>
[
'id' => 1,
'quantity' => 5,
'ipo_item_pml_info' =>
[
'id' => 1,
'product_name' => 'Keyboard'
]
]
],
[
'id' => 2,
'serial' => "XXXXXXAA2",
'pd_item_info' =>
[
'id' => 2,
'quantity' => 10,
'ipo_item_pml_info' =>
[
'id' => 2,
'product_name' => 'Keyboard'
]
]
]
];
and I need to have this output:
$output = [
'product_name' => "Keyboard",
'serial' => ["XXXXXXAA1", "XXXXXXAA2"]
];
Using foreach and array_push in Laravel, how can I merge duplicate product_name values and join their serial values?