#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171

    Access array element in session


    Hi;

    Is there a better way to access element "email"? I currently do echo $data['email'], not cool.
    PHP Code:
    $sess_array = array();
                             foreach(
    $result as $row)
                                 {
                                   
    $sess_array = array(
                                     
    'id' => $row->id,
                                     
    'username' => $row->username,
                                     
    'email' => $row->email,
                                     
    'logged_in' => TRUE
                                   
    );
                                   
    $this->session->set_userdata('logged_in'$sess_array);
                                 }
                                
    $data $this->session->userdata('logged_in');
                                echo 
    $data['email']; 
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,296
    Rep Power
    9400
    Besides using $row->email?

    Not until PHP 5.5 I think, no. You could extend userdata() to, say, allow for specifying the top key if the data is an array.
    PHP Code:
    echo $this->session->userdata('logged_in''email'); 

IMN logo majestic logo threadwatch logo seochat tools logo