syntax to access an index of the session variable directly? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: syntax to access an index of the session variable directly? (/showthread.php?tid=40827) |
syntax to access an index of the session variable directly? - El Forum - 04-19-2011 [eluser]stormbytes[/eluser] Looking for the lazy way out... Assuming 'user' is an array stored in the session via $this->session->set_userdata('user'); Assuming $user has an index 'id', which would normally be accessed via $user['id'] Is there a way to structure a call to the session that would retrieve only the 'id' index? Tried $this->session->userdata('user')['id']; which didn't work out too well syntax to access an index of the session variable directly? - El Forum - 04-20-2011 [eluser]danmontgomery[/eluser] You can't directly access arrays returned by functions, you have to store it in a variable. Code: if($user = $this->session->userdata('user')) { syntax to access an index of the session variable directly? - El Forum - 04-20-2011 [eluser]stormbytes[/eluser] So much for lazy! Thanks |