inghfs
asked on
PHP shopping carts and Key Value Pairs
I am attempting to create a PHP shopping cart using a session. Below is the code I have so far for adding to the cart.
session_start();
$cart = $_SESSION['cart'];
$cart[sizeof($cart)+1] = $_GET['pid'] ;
$_SESSION['cart'] = $cart;
I want to store the quantity ordered as a key value pair in the array. I have tried this using the below code, without any luck. How do I do this?
$cart[sizeof($cart)+1] = ($_GET['pid'] => $_GET['quantity']);
Many Thanks
session_start();
$cart = $_SESSION['cart'];
$cart[sizeof($cart)+1] = $_GET['pid'] ;
$_SESSION['cart'] = $cart;
I want to store the quantity ordered as a key value pair in the array. I have tried this using the below code, without any luck. How do I do this?
$cart[sizeof($cart)+1] = ($_GET['pid'] => $_GET['quantity']);
Many Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.