Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在多维数组中取消设置值?_Php_Arrays - Fatal编程技术网

Php 如何在多维数组中取消设置值?

Php 如何在多维数组中取消设置值?,php,arrays,Php,Arrays,我试图在用户按下按钮时从多维数组中取消设置一个值。该数组如下所示: array(1) { [1726]=> array(2) { [1736]=> int(1) [1737]=> int(4) } [2314] => array(2) { [1436]=> int(3) [1567]=> int(4) [2457]=> int(7) } } 比如

我试图在用户按下按钮时从多维数组中取消设置一个值。该数组如下所示:

array(1) {
  [1726]=>
  array(2) {
    [1736]=>
    int(1)
    [1737]=>
    int(4)
  }
  [2314] =>
  array(2) {
    [1436]=>
    int(3)
    [1567]=>
    int(4)
    [2457]=>
    int(7)
    }
}
比如说,我正试图让你不安

$_SESSION['cart'][1][1]
到目前为止,我们已经尝试了:

switch ($action) {
    case 'add':
        $_SESSION['cart'][$deb_id][$product_id]++;
        var_dump($_SESSION['cart']); exit();
        break;
    case "remove":
        $_SESSION['cart'][$deb_id][$product_id]--;
        if($_SESSION['cart'][$deb_id][$product_id] == 0) unset($_SESSION['cart'][$deb_id][$product_id]);
    break;
    case 'delete':
        unset($_SESSION['cart'][$deb_id][$product_id]);
    break;
}
怎么样

 $_SESSION['cart'][$deb_id][$product_id] = '';
 unset($_SESSION['cart'][$deb_id][$product_id]);

如果要取消设置,例如
$\u会话['cart'][1][1]
,请使用
取消设置($\u会话['cart'][1][1])
。问题不清楚。您的代码应该可以正常工作。不是吗?如果没有,到目前为止您尝试了什么?你认为问题出在哪里?添加第一行有什么意义?这完全没用。确定要删除吗?我也是新手