Link to home
Start Free TrialLog in
Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on

How to store a get variable into an array?

This seems like a rather silly question, but how do I store a $_GET variable in an array?

I have tried:

$bag = get_item();
		
$_SESSION['cart'] = array();
$_SESSION['cart'] = [$bag];

Open in new window


The problem with this is it only stores the current $_GET variable.  When you move to a different page and click a different product it overwrites the variable.  

So I want to put it in the array (store past $_GET variables) not have it be the only thing in the array.  Anyone know how to do this??
Avatar of jason987
jason987

$_SESSION['cart'] = $_GET['item'];
ASKER CERTIFIED SOLUTION
Avatar of enachemc
enachemc
Flag of Afghanistan 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
Avatar of FairyBusiness

ASKER

Thanks :)
Of course you would want to track the number of items in the cart by doing something like setting $_SESSION['numitems'] so you know what array item you are working with.
hmmm ok that can be my next question jason if you want to answer it!