我如何添加1到數量如果它不是新條目,並且如果它是新項目,它只會將項目添加到session['cart']
,我試圖將其添加到session['cart']['qty']
。如果In_array是真的,使用PHP
if (!isset($_SESSION['cart'])) {
$item = array('pid' => $p['productID'],
'qty' => 1
);
$_SESSION['cart'][0] = $item;
} else {
$item_id = array_column($_SESSION['cart'], "pid");
if (in_array($p['productID'], $item_id)) {
$to_update = 'qty';
$new_qty = 5;
$base = $_SESSION['cart']['pid']['qty'];
} else {
$count = count($_SESSION['cart']);
$item = array('pid' => $p['productID'],
'qty' => 1
);
$_SESSION['cart'][$count] = $item;
}
}
實際上會發生什麼? – SteveFest