![]() |
Easiest way to acces an array with session->userdata - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Easiest way to acces an array with session->userdata (/showthread.php?tid=34388) |
Easiest way to acces an array with session->userdata - El Forum - 09-28-2010 [eluser]Unknown[/eluser] Hi Guys, One of the problems I encounter is retrieving a value of an array within a session. I will give you an example: <?php /* SET SOME DATA */ $arr_person = array('firstname' => 'Danny', 'lastname' => Klaassen', 'initials' => 'D'); $arr_login = array('username' => 'dklaassen', 'rank' => 1); $arr_data = array('person' => $arr_person, 'login' => $arr_login); $this->session->set_userdata($arr_data); ?> What if I want to check the users rank. Now I use the following code: <?php /* Check user rank bitwise */ $arr_user = $this->session->userdata('login'); if ($arr_user['rank'] & 1) { ... } else { ... } ?> I prefer to access the rank immediately, without the intervention of $arr_user. Is there any way to achieve that? Easiest way to acces an array with session->userdata - El Forum - 09-28-2010 [eluser]Enéas Gesing[/eluser] Yes, Just do: $this->session->userdata['login']['rank']; Easiest way to acces an array with session->userdata - El Forum - 09-28-2010 [eluser]Unknown[/eluser] Damn... so easy... Thnkz for helping me out |