Link to home
Start Free TrialLog in
Avatar of inghfs
inghfsFlag for United Kingdom of Great Britain and Northern Ireland

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
ASKER CERTIFIED SOLUTION
Avatar of glcummins
glcummins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial