我正在做一个电子商务系统。这就是填充数组的样子: [0] => Array ( [0] => 1 (this is the id) [1] => 1 ((this is the quantity) [2] => abcd (this some一种 txt 框)[3] => 10(这是价格))
[1] => Array
(
[0] => 3
[1] => 1
[2] => efg
[3] => 50
)
[2] => Array
(
[0] => 1
[1] => 1
[2] => bla bla bla
[3] => 10
)
现在我需要检查何时插入 id 是否存在,如果它只是和数量。这是代码:
if (!empty($_SESSION["cart"])) {
$array = $_SESSION['cart'];
$item = array($_POST['id'], $_POST["quantity"], $_POST['txt'], $_POST['price']);
array_push($array, $item);
$_SESSION["cart"] = $array;
} else {
$_SESSION["cart"] = array(array($_POST['id'], $_POST["quantity"], $_POST['txt'], $_POST['price']));
}