[PHP] Dynamic Multi Dimensional Arrays
Hello Everyone, I want to emulate session objects (as opposed to variables). I stumbled upon creating multi-dimensional arrays, so I can do this: $name = 'Bob'; $year = '2003'; $HTTP_SESSION_VARS[$user][$year] = 'registered'; which gives $HTTP_SESSION_VARS['Bob']['2003'] = 'registered'; but I want to append an options array in this so what I want is: $options = array ( 'income' = 1, 'age' = 25 ); $HTTP_SESSION_VARS[$user][$options] = 'registered'; which gives: $HTTP_SESSION_VARS['Bob'][ [income]=1, [age]=25 ] = 'registered'; but this doesn't work. Is there any way I can have objects saved in sessions? Bobby -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic Multi Dimensional Arrays
Hello Everyone, I want to emulate session objects (as opposed to variables). I stumbled upon creating multi-dimensional arrays, so I can do this: $name = 'Bob'; $year = '2003'; $HTTP_SESSION_VARS[$user][$year] = 'registered'; which gives $HTTP_SESSION_VARS['Bob']['2003'] = 'registered'; but I want to append an options array in this so what I want is: $options = array ( 'income' = 1, 'age' = 25 ); (Where the $options array is created dynamically from passed POST data). $HTTP_SESSION_VARS[$user][$options] = 'registered'; which gives: $HTTP_SESSION_VARS['Bob'][ [income]=1, [age]=25 ] = 'registered'; but this doesn't work. Is there any way I can have objects saved in sessions? Bobby -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Multi Dimensional Arrays
Hi, Tuesday, September 9, 2003, 2:19:28 PM, you wrote: BP Hello Everyone, BP I want to emulate session objects (as opposed to variables). I stumbled BP upon creating multi-dimensional arrays, so I can do this: BP $name = 'Bob'; BP $year = '2003'; BP $HTTP_SESSION_VARS[$user][$year] = 'registered'; BP which gives $HTTP_SESSION_VARS['Bob']['2003'] = 'registered'; BP but I want to append an options array in this so what I want is: BP $options = array ( BP'income' = 1, BP'age' = 25 BP ); BP $HTTP_SESSION_VARS[$user][$options] = 'registered'; BP which gives: BP$HTTP_SESSION_VARS['Bob'][ [income]=1, [age]=25 ] = 'registered'; BP but this doesn't work. Is there any way I can have objects saved in BP sessions? BP Bobby you would have to give $user another key value $options = array('income'=1.'age'=25); $HTTP_SESSION_VARS[$user] = $options; $HTTP_SESSION_VARS[$user]['status'] = 'registered'; also in these cases print_r($HTTP_SESSION_VARS[$user]) can be your friend. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Multi Dimensional Arrays
Bobby Patel wrote: Hello Everyone, I want to emulate session objects (as opposed to variables). I stumbled upon creating multi-dimensional arrays, so I can do this: $name = 'Bob'; $year = '2003'; $HTTP_SESSION_VARS[$user][$year] = 'registered'; which gives $HTTP_SESSION_VARS['Bob']['2003'] = 'registered'; but I want to append an options array in this so what I want is: $options = array ( 'income' = 1, 'age' = 25 ); $HTTP_SESSION_VARS[$user][$options] = 'registered'; which gives: $HTTP_SESSION_VARS['Bob'][ [income]=1, [age]=25 ] = 'registered'; but this doesn't work. Is there any way I can have objects saved in sessions? There is, but I am not sure that is what you want. The reason you are getting the above result is because you are using $object (which is an array) as a key. Do you want an array element that holds the $options array? $HTTP_SESSION_VARS[$user]['options'] = $options; You could then add elements to this array like this: $HTTP_SESSION_VARS[$user]['options']['registered'] = 1; Is that what you are trying to do? - Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Multi Dimensional Arrays
Brad Pauly wrote: $HTTP_SESSION_VARS[$user]['options'] = $options; yes this is what I wanted. You could then add elements to this array like this: $HTTP_SESSION_VARS[$user]['options']['registered'] = 1; Is that what you are trying to do? - Brad I will try this out and see what happens. Thank you Tom and Brad. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php