RE: [PHP] Can I name a session variable using another variable?
| From: | Ed Lazor | Date: | Mon, 13 Sep 2004 18:15:25 +0000 |
| Subject: | RE: [PHP] Can I name a session variable using another variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196542@lists.php.net to get a copy of this message | ||
Here's another option as well, in case it helps out:
$var1 = "Pizza";
$var2 = "var1";
$var3 = $$var2;
print "var3 = $var3<br>";
Output:
var3 = Pizza
> -----Original Message-----
> Ok, assuming everything's working correctly except for the use of
> $prevtime in the SESSION, then here's one answer:
>
> Yes, you can name a session the way you described. If you're having
> trouble with doing the concatenation of values inside $_SESSION, then
> try combining them outside:
>
> $roomname="sampleroom";
> $sessionname = $roomname . $prevtime;
> $_SESSION[$sessionname]=time();
>
>
> Secondly, looks like you forgot a "$" on prevtime below:
> $_SESSION["$roomname" . "prevtime"]=time();
>
> Thirdly, you can store arrays in $_SESSION as well, so you could divide
> the rooms up that way:
>
> $_SESSION[$roomname]["PrevTime"] = $prevtime;
>
>
> -TG