Page 1 of 1

Problem setting array as a session variable - urgent help.

Posted: Mon Apr 12, 2004 6:19 am
by gaurav_sting
hi everyone,

i am trying to set a session variable (array) but unable to figure out how to do that. I am able to set a single variable but i need to set an array.

for instance i am alble to do following:
session_start();
$cart = array();
$_SESSION['cart'] = '1234';

but i want to set the value(index) of the cart array also. for instance:
session_start()
$cart = array();

Now supossingly, i set an index for the cart array.
$cart['isbn'] = '1234';

Now i am not able to set cart index as a session variable.
i tried this, but was unable to get how to set the array along with the index.
$_SESSION[$cart['isbn']] = '1234';

i wrote this but got error. I do not want to use session_register, instead i want to use $_SESSION super globals as it is more secure.

Thanx.
Gaurav

Posted: Mon Apr 12, 2004 6:29 am
by andre_c
Try this:

Code: Select all

$_SESSION['cart']['isbn'] = '1234';
$_SESSION['cart']['other'] = 'blah';
... since $_SESSION is an array, now you made it a multi-dimesional array. (array of arrays)