好吧,这里是我的代码来编辑数组中的特定条目,并且数组布局如下。数组编辑无法正常工作
$counter = 0;
foreach($_SESSION['cart'] as $listitem){
if ($listitem[0] == $_POST['product']){
if ($listitem[1] <= $_POST['remove']){
$remove = array($listitem[0], 0);
$_SESSION['cart'][$counter] = $remove;
} else {
$result = $listitem[1] - $_POST['remove'];
$remove = array($listitem[0], $result);
$_SESSION['cart'][$counter] = $remove;
}
}
$counter = $counter++;
}
这里是我的$_SESSION['Cart']
阵列布局
Array(
- [0] => Array ([0] => 8 [1] => 0)
- [1] => Array ([0] => 10 [1] => 0)
- [2] => Array ([0] => 8 [1] => 1)
)
,要么是我数组的理解是错误的这行代码:
$_SESSION['cart'][$counter]
还是我的柜台将不计算:
$counter = $counter++;
因为它保持编辑第一个条目的唯一值[0]
任何人都可以看到我出错的地方吗?
将'$ counter = $ counter ++'改为'$ counter ++'或'$ counter = $ counter + 1'或'$ counter + = 1'或'++ $ counter'等。 – Jonathon 2015-03-13 13:31:11
请阅读[increment and递减运算符](http://php.net/manual/en/language.operators.increment.php)。 – 2015-03-13 13:32:29
感谢所有的答案,白痴新手的错误,有一件事一直困扰我超过一个小时.. – PirateScott 2015-03-13 13:42:10