What would be the best way to group repeated values of an array like this:
$array = [
0 => ['id'=>1, 'name'=>'prod1', 'type'=>'a', 'price'=>2.50],
1 => ['id'=>1, 'name'=>'prod1', 'type'=>'b', 'price'=>5.50],
2 => ['id'=>1, 'name'=>'prod1', 'type'=>'c', 'price'=>10.50],
3 => ['id'=>2, 'name'=>'prod2', 'type'=>'a', 'price'=>3.50],
4 => ['id'=>2, 'name'=>'prod2', 'type'=>'b', 'price'=>7.50]
];
in order to get an output array like so:
$sorted_array = [
0 => ['id'=>1, 'name'=>'prod1', 'type'=>['a' => ['price'=>2.50],
'b'=> ['price'=>5.50],
'c'=> ['price'=>10.50]
]
],
1 => ['id'=>2, 'name'=>'prod2', 'type'=>['a'=>['price'=>3.50],
'b'=>['price'=>7.50]
]
]
];