【发布时间】:2015-04-02 10:19:00
【问题描述】:
我试图从一个多数组中删除一个 session['cart_items] 数组,但我似乎无法让删除部分工作。
我正在通过:$_POST['product] 获取 ID,但是我尝试了以下操作并有点卡住:
$temp = array_flip($_SESSION['cart_items']);
unset($_SESSION['cart_items'][$temp[$_POST['product']]]);
我也试过了:
unset($_SESSION['cart_items'][$key]);
我的输出是:
Array
(
[0] => Array
(
[0] => Array
(
[item_id] => 407
[item_name] => Am I Bothered? About Homophobia
[item_qty] => 22
)
)
)
帮助会很大
多个数组结果:
array(1) {
["cart_items"]=>
array(2) {
[1]=>
array(1) {
[0]=>
array(3) {
["item_id"]=>
string(3) "407"
["item_name"]=>
string(31) "Am I Bothered? About Homophobia"
["item_qty"]=>
string(2) "50"
}
}
[2]=>
array(1) {
[0]=>
array(3) {
["item_id"]=>
string(4) "1131"
["item_name"]=>
string(50) "10 Ways A Condom Can’t Protect You – Postcards"
["item_qty"]=>
string(2) "14"
}
}
}
}
【问题讨论】:
-
$_SESSION['cart_items'][$key] = ""? -
$key=array_search($_POST['product'],$_SESSION['cart_items']);
-
$key 值是多少?它是相同的数组索引吗?
-
我的意思是用那个代替
unset() -
是的,试图删除 item_id = $_POST['product'] 的数组