I have the following PHP array. It store the information of a certain item, the store id and the price for that store. This array will be dynamic, so later more store_ids will be added.
array (size=6)
0 =>
array (size=3)
'item_id' => '1'
'store_id' => '1'
'price' => '74.99'
1 =>
array (size=3)
'item_id' => '2'
'store_id' => '1'
'price' => '35.99'
2 =>
array (size=3)
'item_id' => '3'
'store_id' => '1'
'price' => '89.99'
3 =>
array (size=3)
'item_id' => '1'
'store_id' => '2'
'price' => '69.99'
4 =>
array (size=3)
'item_id' => '2'
'store_id' => '2'
'price' => '39.99'
5 =>
array (size=3)
'item_id' => '3'
'store_id' => '2'
'price' => '95.99'
This is the result I want to get, I want to group them by the item_id and store every price each item has at every store. All the items will be available in all the store_ids.
array (size=3)
0 =>
array (size=3)
'item_id' => '1'
(price for store_id 1) => '74.99'
(price for store_id 2) => '69.99'
1 =>
array (size=3)
'item_id' => '2'
(price for store_id 1) => '35.99'
(price for store_id 2) => '39.99'
2 =>
array (size=3)
'item_id' => '3'
(price for store_id 1) => '89.99'
(price for store_id 2) => '95.99'
I was trying to do this directly from the query but I am using mysql and didn't find a solution for that. I know I need to loop through the array but I have no clue about the process needed to achieve this. Any help or suggestion is appreciated. Thanks!