|Array being reset rather than added to|
I have some values that I am getting from a form users fill out. I am grabbing these values and storing them into sessions like so
$_SESSION['id'] = $_GET['id'];
Next, I'm storing those sessions into an array, like this
$array = array(
'model' => $_SESSION['model'],
'qty' => $_SESSION['qty'],
'id' => $_SESSION['id'],
I'm then trying to store that array, in another array. Like this
$other_array = Array(
"ID" => $array,
This works for the values that I submit from the form the first time around. When I submit different values from the same form I want it to create another array using the GET values and then store that in my $other_array.
Currently, it just replaces the first array that is added.
How can I get it to add another array rather than replacing it?
Hi there algalogica, and a very warm welcom to WebmasterWorld!
Firstly, are you aware that $_SESSION is in it's very nature an array anyway, anything that has: ['somevalue'] is a reference to an element within an array.
If you did Print_r($_SESSION); you would see what I mean.
The way you're trying to do this would require multidimensional arrays, so that you could create a sort of look-up table for your sessions and the values.
Have a quick google for that and I'm sure that you'll find lots of tips on that.
(from a very tired)
I'm reading this as thinking every time the user submits this form, it adds to an array of previously submitted data?
In that case, you don't need to specify a specific key for your $other_array. You can use a variable key, or just let it decide on keys by itself:
// Let it decide it's own key.
// First submission has key 0
// Next has key 1 etc..
$other_array = $array;
// Or you can use something posted in the form
$other_array[$_GET['id']] = $array;
Also, hi Matt! :)
Thank you very much Matthew and Readie, these answers helped me solve my problem!