Sorry if this is a duplicate but I tried my hardest to find a similar question but I wasn't 100% sure what exactly to search for.
The array below is from an e-commerce site I am creating. Each item has colour variants with a unique item code, however items share a sku. I would like to merge the array by the sku code to calculate the quantity of each item. I have seen ways to merge arrays with the same key but can't find a way to merge these.
Thanks
array(4) {
["ITEM-CHAIR-v-V0002"]=>
array(4) {
["itemcode"]=> string(16) "ITEM-CHAIR-v-V0002"
["sku"]=>string(8) "ITEM-CHAIR"
["quantity"]=>string(1) "4"
["price"]=>string(5) "49.99"
}
["ITEM-CHAIR-v-V0003"]=>
array(4) {
["itemcode"]=>string(16) "ITEM-CHAIR-v-V0003"
["sku"]=>string(8) "ITEM-CHAIR"
["quantity"]=>string(1) "7"
["price"]=>string(5) "49.99"
}
["ITEM-KNIFE-v-V0001"]=>
array(4) {
["itemcode"]=>string(22) "ITEM-KNIFE-v-V0001"
["sku"]=>string(14) "ITEM-KNIFE"
["quantity"]=>string(1) "1"
["price"]=>string(5) "45.00"
}
["ITEM-CHAIR-v-V0001"]=>
array(4) {
["itemcode"]=>string(16) "ITEM-CHAIR-v-V0001"
["sku"]=>string(8) "ITEM-CHAIR"
["quantity"]=>string(1) "4"
["price"]=>string(5) "49.99"
}
}