Jump to content

Array As A Session Variable?


cyber0ne

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...