2

i am facing an issue to add multidimensional array to codeigniter session.

i want to store a multidimensional array result to session or any other that variable i used after my adding process i want use that variable.

also tried to store simple array to store in session and they works but in my array this is notworking so please help friends

Please check below for my array structure,

Thanks in advance!

Array
(
   [0] => Array
   (
       [user_id] => 11
       [fb_id] => 0
       [am_id] => 0
       [cm_id] => 
   )
)
4
  • 2
    What did you try? Commented Apr 25, 2017 at 10:51
  • use jsonencode to convert this array to json string and save it to session. And use json decode to convert the string back to array. I guess session do not store datastructues, it stores string values Commented Apr 25, 2017 at 10:52
  • can you please a give a example..thanks Commented Apr 25, 2017 at 11:08
  • Thanks brother...it's working Commented Apr 25, 2017 at 11:30

1 Answer 1

3

Use serialize method before storing multidimensional array to session. It is the better idea for storing multi dimensional array to session as a string and you can access this whenever needed by unserialize method.

Sign up to request clarification or add additional context in comments.

10 Comments

you call like this $this->session->set_userdata('findcaddie',serialize($array_mail));
yes array stored in session but i can't access to this to other page
$user_data = unserialize($this->session->userdata('findcaddie')); echo $user_data['user_id']; like this. not tested this
i have an issue with my data is not stored in session
$user_data = unserialize($this->session->userdata('findcaddie')); not working
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.