Ich kann diese Sitzung Werte festlegen.Session-Wert nicht anderen Schlüssel und ihren Wert
<?php
$_SESSION['cart_items'][$name]['price']=$price;
if (!empty($quantity)) {
$_SESSION['cart_items'][$name]['quantity']=$quantity;
}
?>
Aber wenn ich laufen diese
<?php
foreach($_SESSION['cart_items'] as $key => $value) {
echo $key ;
echo $value;
//echo "<br>prod product_price : ".$product_price;
}
?>
Es druckt nur die $_SESSION['cart_items'][$name]['price']
. Es druckt nicht den Mengenwert. Wie kann ich mich wie für die $name
den Preis, Menge drucken usw.
Hier ist mein vollständiger Code:
if(!isset($_SESSION['cart_items'])){
$_SESSION['cart_items'] = array();
}
// check if the item is in the array, if it is, do not add
if(array_key_exists($id, $_SESSION['cart_items'])){
// redirect to product list and tell the user it was added to cart
header('Location: products.php?action=exists&id' . $id . '&name=' . $name);
}
// else, add the item to the array
else{
$_SESSION['cart_items'][$name]['price']=$price;
if (!empty($quantity)){
echo "adding qty";
$_SESSION['cart_items'][$name]['quantity']=$quantity;
}
// redirect to product list and tell the user it was added to cart
// header('Location: products.php?action=added&id' . $id . '&name=' . $name);
}
Bist Du sicher, dass '$ _SESSION [ 'cart_items'] [$ name] [ 'Menge'] 'wird eingestellt? Ich würde zuerst testen, ob die Ausführung auf diesem konditionalen – ReynierPM
eintritt. – user5313398
Fügen Sie die Ausgabe von 'var_export ($ _ SESSION ['cart_items']' auf dem Hauptpostpls – ReynierPM