会话中的访问数组变量(CodeIgniter) [英] Access array variable in session (CodeIgniter)
本文介绍了会话中的访问数组变量(CodeIgniter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为config的数组。我试图在会话中回显数组中的一个变量。
I have an array called config. I'm trying to echo a variable from the array in the session.
我试过:
echo $this->session->userdata('config['item']');
但不起作用。这里的语法有什么问题?我已经打印了我的会话,项目在config数组。我也试过:
but it doesn't work. What's wrong with my syntax here? I've print_r'd my session and the items are in the config array. I've also tried:
echo $this->session->userdata("config['item']");
我没有错误,但是没有数据。
I get no errors this time, but no data either.
推荐答案
如果config是一个数组。而item是您想从配置中获取的字符串名称
If config is an array . And item is string name of what you want to get from config then
echo $this->session->userdata($config['item']);
或
echo $_SESSION[$config['item']];
如果config是会话中的数组,你应该先获取它。
If config is an array inside session you should first get it.
$tmp = $this->session->userdata('config');
echo $tmp['item'];
或
echo $_SESSION['config']['item']
。
这篇关于会话中的访问数组变量(CodeIgniter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文