two dimension session issue with codeigniter

喜欢而已 提交于 2020-01-03 02:56:56

问题


I want to store two dimensional array in session, where i keep creating the array through a function call.

I am trying with this code

function nextQuestion($questionId,$response)
{ 
       $this->session->set_userdata("res[$questionId][]"),$response);
}

but this is not creating a two dimensional array


回答1:


The key stored in the session must be a string but the value can be a multi dimensional array. You can retrieve the array, manipulate it and save it in the session again like this:

$session_response = $this->session->userdata("res");
//some manipulation on $session_response
$this->session->set_userdata('res', $session_response);



回答2:


sametimes codeigniter session library can be boring. if i add array to session, i serialize the array.

You can serialize array and get back with unserialize. or you can use php session library.



来源:https://stackoverflow.com/questions/10763557/two-dimension-session-issue-with-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!