我正在处理添加到购物车模块,我最终得到的会话数组是这样的:
Array
(
[cart] => Array
(
[0] => Array
(
[item] => Array
(
[item_name] => burger
[item_price] => 5
[item_qty] => 3
)
)
[1] => Array
(
[item] => Array
(
[item_name] => pizza
[item_price] => 15
[item_qty] => 2
)
)
[2] => Array
(
[item] => Array
(
[item_name] => french fries
[item_price] => 8
[item_qty] => 5
)
)
)
)
我想从这个数组中删除一个项目,说出名称为" pizza"的项目。我该怎么办?
答案 0 :(得分:3)
function rem_from_array(&$session_array, $name)
{
foreach($session_array as $key=>$elem)
if($elem['item']['item_name']==$name)
{
unset($session_array[$key]);
return;
}
}
然后你应该只执行以下代码:
rem_from_array($_SESSION['cart'], 'pizza');