Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to store a get variable into an array?

Posted on 2011-04-28
5
Medium Priority
?
400 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??
0
Comment
Question by:FairyBusiness
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:jason987
ID: 35487785
$_SESSION['cart'] = $_GET['item'];
0
 
LVL 12

Accepted Solution

by:
enachemc earned 2000 total points
ID: 35487793
$bag = get_item();
            
if(!isset($_SESSION['cart']))$_SESSION['cart'] = array();
array_push($_SESSION['cart'], $bag);
0
 

Author Closing Comment

by:FairyBusiness
ID: 35487807
Thanks :)
0
 
LVL 5

Expert Comment

by:jason987
ID: 35487828
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.
0
 

Author Comment

by:FairyBusiness
ID: 35487834
hmmm ok that can be my next question jason if you want to answer it!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question