• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
syntax to access an index of the session variable directly?

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 Smile

You can't directly access arrays returned by functions, you have to store it in a variable.

if($user = $this->session->userdata('user')) {
    $id = $user['id'];

So much for lazy! Smile Thanks

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.