Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storring arrays in Sessions

Status
Not open for further replies.

rrsub

MIS
Joined
Oct 23, 2002
Messages
536
Location
US
I must be doing this wrong.

I have this variable which is $cat[$i]['m'] which is different dependent upon whatever the value of $i is.

I want to store this as a session variable which I think I do by

$_SESSION['cat[$i][m]'] = $cat[$i]['m'];

That doesn't work.
$i=2;
echo $_SESSION['cat[$i][m]'];

is different from

echo $_SESSION['cat[2][m]'];

Can someone point me in the right direction?
 
Have you tried the 'variable variables' feature?


I think that's what you are looking for(try [$$i]). Then again, I'm probably totally off. Think I'm getting the flu, a little dizzy :-)

----
JBR
 
The problem is your use of quotes inside the array refence. Those single quotes tells PHP to store the value in an array element named, literally, "$cat[$i]['m']". It's not storing any kind of array.

You're trying to store a single value of an array in a session variable, but still preserve the array?

You could just store the single value:

$_SESSION['fromcat'] = $cat[$i]['m'];

or just store the entire array, if you're going to need to access multiple values in later scripts.:

$_SESSION['cat'] = $cat;




Want the best answers? Ask the best questions: TANSTAAFL!!
 
sleipnir24,

I slept on it and the solution I came up with is the latter of your choices.


Thanks. I kinda felt I was doing it wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top