我在多维数组中面临一个问题。如果选择的ID和变体都与会话产品之一相同,则我需要在会话中更改特定产品集的数量,然后将此产品加1。
我发布的产品 $newproduct
Array
(
[id] => 2
[title] => Vewlix 1080p (red and white)
[image] => amazing-modern-villa-Freshome-02.jpg
[variants] => Array
(
[0] => Array
(
[id] => 2
[option_name] => Panel 2 players (+50 euros)
[option_price] => 50.00
)
)
[quantity] => 1
[unit_price] => 1950.00
[price] => 2000
)
这是我的$_SESSION['shopping_cart']:
Array
(
[0] => Array
(
[id] => 2
[title] => Vewlix 1080p (red and white)
[image] => amazing-modern-villa-Freshome-02.jpg
[variants] => Array
(
[0] => Array
(
[id] => 1
[option_name] => Panel 1 player
[option_price] => 0.00
)
)
[quantity] => 2
[unit_price] => 1950.00
[price] => 1950
)
[1] => Array
(
[id] => 2
[title] => Vewlix 1080p (red and white)
[image] => amazing-modern-villa-Freshome-02.jpg
[variants] => Array
(
[0] => Array
(
[id] => 2
[option_name] => Panel 2 players (+50 euros)
[option_price] => 50.00
)
)
[quantity] => 1
[unit_price] => 1950.00
[price] => 2000
)
)
现在,我可以使用ID和变体比较,但是在发布类似产品时,不是仅增加具有相同ID /变体的特定产品,而是将会话中的所有产品数量增加+1。
如何只为具有完全相同的ID /变体的产品添加+1?我认为我的[$ key]不起作用,因为它应该是仅增加适当产品数量的过滤器
蓝山帝景