We help IT Professionals succeed at work.

How to store a get variable into an array?

FairyBusiness
on
Medium Priority
410 Views
Last Modified: 2012-05-11
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??
Comment
Watch Question

Commented:
$_SESSION['cart'] = $_GET['item'];
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks :)

Commented:
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.

Author

Commented:
hmmm ok that can be my next question jason if you want to answer it!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.