I would like to set a session variable with something akin to:
$key = '_SESSION[element]';
$$key = 'value';
This does indeed set $_SESSION['element']
equal to value
, but it also seems to clear the rest of my $_SESSION
variable, resulting in the $_SESSION
array only containing the new key/value pair.
How can I write into the session using variable variables without nuking it?
Edit: if this can't be done, so be it, we'll probably have to restructure and do things the "right" way. I just wanted to know if there was an easy fix
From PHP Documentation:
How you ended up with a situation like this, is really questionable. You're probably doing something wrong.
EDIT
This little trick should give you what you want:
This will basically produce the same results as xdazz's answer
Isn't this way better?
@Mala, I think eval will help you. Check the code below. It may help you for what you want.
If you still have any trouble, Let me know. Thank you