Gustavo
Gustavo

Reputation: 311

name a session with variable

Well what i want to do is , fetch a value from a database and asign it to a session name something like this

$_SESSION[$fetch[0]['name']]=some_value;

i dont know if im able to do that but it'll be quite usefull to me.

Upvotes: 0

Views: 593

Answers (2)

RobertPitt
RobertPitt

Reputation: 57268

Short answer is yes you can do that, but i would advise you to set a static value such as:

$_SESSION["name"] = $fetch[0]['name'];

and then you can just use $_SESSION["name"] to get the value.

everything written in the php is classed as hard code, you should be aware that setting dynamic content as array keys are usually unreliable.

Upvotes: 2

Daniel A. White
Daniel A. White

Reputation: 190976

Why not? As long as you can still use the value that is returned by $fetch[0]['name']...

Upvotes: 1

Related Questions