codeigniter的会话数组操作 [英] Array Manipulation of Codeigniter's Sessions
本文介绍了codeigniter的会话数组操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
继续
喜的家伙。我使用codeigniter,并希望将数据存储在会话中。我有这样的阵列
Hi guys. I am using codeigniter and want to store data in the session. I have this array
array(4) {
[0]=> array(2) { ["DESC"]=> string(1) "A" ["SUBFUNCTION_ID"]=> string(3) "904" }
[1]=> array(2) { ["DESC"]=> string(1) "B" ["SUBFUNCTION_ID"]=> string(3) "903" }
[2]=> array(2) { ["DESC"]=> string(1) "C" ["SUBFUNCTION_ID"]=> string(3) "902" }
[3]=> array(2) { ["DESC"]=> string(1) "D" ["SUBFUNCTION_ID"]=> string(3) "901" }
}
和这是存储会话数据阵列
And this is the array to store the session data
$data = array(
'username' => $this->input->post('username'),
'userid' => $query->USER_ID,
'role' => $query->ROLE_ID,
'is_logged_in' => true
);
如何操作的第一个数组,然后将数据追加到第二个数组?我希望它成为像这样
How can i manipulate the first array and then append the data into the second array? I want it to become something like this
$data = array(
'username' => $this->input->post('username'),
'userid' => $query->USER_ID,
'role' => $query->ROLE_ID,
'is_logged_in' => true,
'A' => 904,
'B' => 903,
'C' => 902,
'D' => 901
);
在此先感谢
推荐答案
这听起来像你有你的会话数据在 $ foo的
的形式,并开始数据 $数据
It sounds like you have your session data in the form of $foo
and starting data $data
$foo = array (
array('DESC'=>'A', 'SUBFUNCTION_ID'=>904),
array('DESC'=>'B', 'SUBFUNCTION_ID'=>903),
array('DESC'=>'C', 'SUBFUNCTION_ID'=>902),
array('DESC'=>'D', 'SUBFUNCTION_ID'=>901),
);
$data = array(
'username' => $this->input->post('username'),
'userid' => $query->USER_ID,
'role' => $query->ROLE_ID,
'is_logged_in' => true
);
要在从 $ foo的
将数据合并到 $数据
为你的要求,循环遍历所有值 $ foo的
,然后将它们附加到 $数据
To merge in the data from $foo
into $data
as you requested, loop over all values in $foo
and then append them to $data
foreach($foo as $bar) {
$data[$bar['DESC']] = $bar['SUBFUNCTION_ID'];
}
这篇关于codeigniter的会话数组操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文