cyber0ne Posted October 11, 2006 Share Posted October 11, 2006 Can PHP store an array as a value in a session variable? The following code seems to suggest that it can't since it gives me an error, but I wonder if there's maybe something else I just need to do or if someone has figured out a way to at least achieve the same functionality: $_SESSION["UserGroups"] = {function that returns an array};$temp = $_SESSION["UserGroups"];echo $temp[count($temp) - 1];exit; Is this something that can't be done by design, or is there a way to have an array follow a session? I did notice that count($temp) is 2 in the above code (though the original array returned by the function had 5 elements), but I don't know why... Link to comment Share on other sites More sharing options...
aspnetguy Posted October 11, 2006 Share Posted October 11, 2006 I found this example showing arrays can be sotred in a Session variable <?phpsession_start();$myarray = array('value1','value2','value3');$_SESSION['user_info'] = $myarray;?> does that work? Link to comment Share on other sites More sharing options...
cyber0ne Posted October 11, 2006 Author Share Posted October 11, 2006 does that work?Indeed it does... I guess the problem lies elsewhere. I know that function is returning a 5-element array. Maybe I have a typo somewhere or something simple like that.In any event, you've given me something to go on. Thanks Link to comment Share on other sites More sharing options...
aspnetguy Posted October 11, 2006 Share Posted October 11, 2006 Indeed it does... I guess the problem lies elsewhere. I know that function is returning a 5-element array. Maybe I have a typo somewhere or something simple like that.In any event, you've given me something to go on. Thanks well if you are still stuck post the function code aswell adn I'll see if I can spot a mistake. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 11, 2006 Share Posted October 11, 2006 Are you starting the session? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now