I’m really stuck for ideas on how to do this, so I’m not exactly sure what to ask for, but here goes.
This is what I have so far:
foreach($order as $key => $ord){
$attribute = explode(":", $order[$key]);
echo sku($attribute[0],$attribute[2],$attribute[1],$attribute[4])." - ".$attribute[3].";
}
The output of this will be something like
SKU - QUANTITY
1001-01 - 5
1001-02 - 3
1001-01 - 1
1045-02 - 1
1001-02 - 8
1001-01 - 3
1003-01 - 4
I need a way of totalling these so it shows
SKU - QUANTITY
1001-01 - 9
1001-02 - 11
1003-01 - 4
1045-02 - 1
Is this possible?
Yes, it’s possible. Just use an array with the sku as the key:
On a side note:
explodebeing required to do things like this often implies that the data is not being stored in the proper format.Also,
$order[$key]is the exact same thing as$ord, so I’m not sure why you’re using$order[$key].