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


Trying to remove session array from array PHP

我试图从多数组中删除会话['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"
  }
}
}
}
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']);
}