Following is the input array:
$input = [
[
'id' => 96,
'shipping_no' => 212755-1,
'part_no' => 'reterty',
'description' => 'tyrfyt',
'packaging_type' => 'PC'
],
[
'id' => 96,
'shipping_no' => 212755-1,
'part_no' => 'dftgtryh',
'description' => 'dfhgfyh',
'packaging_type' => 'PC'
],
[
'id' => 97,
'shipping_no' => 212755-2,
'part_no' => 'ZeoDark',
'description' => 's%c%s%c%s',
'packaging_type' => 'PC'
]
];
I want the above to be transformed into like this:
$output = [
[
'key' => 96,
'value' => [
[
'shipping_no' => 212755-1,
'part_no' => 'reterty',
'description' => 'tyrfyt',
'packaging_type' => 'PC'
],
[
'shipping_no' => 212755-1,
'part_no' => 'dftgtryh',
'description' => 'dfhgfyh',
'packaging_type' => 'PC'
]
]
],
[
'key' => 97,
'value' => [
[
'shipping_no' => 212755-2,
'part_no' => 'ZeoDark',
'description' => 's%c%s%c%s',
'packaging_type' => 'PC'
]
]
]
];
I have tried to implement it like this:
$result = [];
foreach ($input as $value) {
$result[] = ['key' => $value['id'], 'value' => ['shipping_no' => $value['shipping_no'], 'part_no' => $value['part_no'], 'description' => $value['description'], 'packaging_type' => $value['packaging_type']]];
}
It is not getting grouped based on common key. Please help me with the possible approach that I should take to solve this.