【发布时间】:2017-11-15 09:51:11
【问题描述】:
我目前正在尝试为我的网站创建添加到购物车和从购物车中删除功能。目前,我将用户信息存储在会话变量名称购物车中。 print_r 将以下格式的会话变量返回给我:
Array
(
[0] => Array
(
[productID] => 3
[productTitle] => Life Without Limits
[productAuthor] => Nick Vujicic
[productImg] => nickvujicic/lifewithoutlimits
[productPrice] => 38.00
)
[1] => Array
(
[productID] => 4
[productTitle] => Stand Strong
[productAuthor] => Nick Vujicic
[productImg] => nickvujicic/standstrong
[productPrice] => 25.00
)
)
我能够让添加到购物车功能正常工作,但我目前卡在从购物车中删除功能。当用户单击删除按钮时,该特定产品 ID 将通过 ajax 发送到我的 php 文件,然后我想从那里从购物车数组中删除产品数组。例如,如果我想删除 productID = 3 的产品,购物车数组应该只返回:
Array
(
[0] => Array
(
[productID] => 4
[productTitle] => Stand Strong
[productAuthor] => Nick Vujicic
[productImg] => nickvujicic/standstrong
[productPrice] => 25.00
)
)
我该如何实现这一目标?提前感谢您的帮助!
【问题讨论】:
标签: php arrays session multidimensional-array session-variables