session variables
Moderator: General Moderators
session variables
This is probably a really dumb question but I can't find the answer anywhere else. When I create a session variable ($_SESSION["name"]) is it possible to use a variable for its name ($_SESSION[$name])? The session variable is called frequently and having it predefined at the top of the file would make changes quite easy. Thanks!
- Peter Anselmo
- Forum Commoner
- Posts: 58
- Joined: Wed Feb 27, 2008 7:22 pm
Re: session variables
Using a variable as an index for the session array is perfectly valid.
Code: Select all
$_SESSION['bar'] = "Hello World";
$foo = 'bar'
echo $_SESSION[$foo] //prints "Hello World"