我已經包含產品項的數組,在某些情況下,該產品被添加到購物車兩次,我想刪除重複並添加量一起卸下從購物項目陣列重複,且增加量
該項目需要匹配id
我可以解決這個問題的最佳方法是什麼?
一個例子數組:
Array
(
[0] => Array
(
[type] => fabrication
[id] => 886
[price] => 11.00
[quantity] => 1
[producttitle] => Edge Profiles - Edge Profile B - Single 5mm Radius
[index] => 2
)
[1] => Array
(
[type] => fabrication
[id] => 887
[price] => 11.00
[quantity] => 1
[producttitle] => Edge Profiles - Edge Profile C - Single 19mm Radius
[index] => 3
)
[2] => Array
(
[type] => fabrication
[id] => 887
[price] => 11.00
[quantity] => 10
[producttitle] => Edge Profiles - Edge Profile C - Single 19mm Radius
[index] => 4
)
)
這應成爲:
Array
(
[0] => Array
(
[type] => fabrication
[id] => 886
[price] => 11.00
[quantity] => 1
[producttitle] => Edge Profiles - Edge Profile B - Single 5mm Radius
[index] => 2
)
[1] => Array
(
[type] => fabrication
[id] => 887
[price] => 11.00
[quantity] => 11
[producttitle] => Edge Profiles - Edge Profile C - Single 19mm Radius
[index] => 3
)
)
我的答案以下幫助嗎? – jszobody
它的確如此。感謝一束,芽。 – Ben