用变量命名会话
好吧,我想做的是,从数据库中获取一个值并将其分配给一个会话名称,就像这样
$_SESSION[$fetch[0]['name']]=some_value;
我不知道我是否能够做到这一点,但这对我来说非常有用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是,您可以这样做,但我建议您设置一个静态值,例如:
然后您可以使用
$_SESSION["name"]
来获取该值。PHP 中编写的所有内容都被归类为硬代码,您应该意识到将动态内容设置为数组键通常是不可靠的。
Short answer is yes you can do that, but i would advise you to set a static value such as:
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.
为什么不呢?只要您仍然可以使用
$fetch[0]['name']
返回的值...Why not? As long as you can still use the value that is returned by
$fetch[0]['name']
...