繁体   English   中英

尝试从数组PHP中删除会话数组

[英]Trying to remove session array from array PHP

我试图从多数组中删除一个session ['cart_items]数组,但我似乎无法使delete部分正常工作。

我正在通过以下方式获取ID:$ _ POST ['product],但是我尝试了以下操作并遇到了一些困难:

$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"
  }
}
}
}
for(i=0;i<sizeof($_SESSION['cart_items'][0]);i++){
    if($_SESSION['cart_items'][0][i]['item_id'] == $key);
        unset($_SESSION['cart_items'][0][i]['item_id']);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM