title: How to get Specific Value from Session Array?
body: <p>I have created a session and assigned <code>User_id</code> to the Session Variable. When i use <code>print_r();</code>  it shows me the the session variable data in an associative array but when i use foreach it gives me many error messages.</p>
  
  <p>Kindly check it and guide me what i am doing wrong here.</p>
  
  <pre><code>        print_r($session_dataa= $this-&gt;session-&gt;all_userdata());
  
          Session dataArray ( [session_id] =&gt; 5943ecd761c336e70240b25d37b054b8 
          [ip_address] =&gt; ::1 
          [user_agent] =&gt; Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) 
          Gecko/20100101 Firefox/28.0
          [last_activity] =&gt; 1397982790
          [user_data] =&gt; [41] =&gt; ) 
  </code></pre>
  
  <p>I want to grab <code>[user_data]=&gt; [41]</code> and store in <code>student_id</code> variable. To accomplish this i used foreach loop, but its giving me following error message.</p>
  
  <pre><code>$session_data= $this-&gt;session-&gt;all_userdata();
  
  foreach ($session_data as $data)
  {
      $student_id =   $data-&gt;user_data;
  }
  
  Severity: Notice
  
  Message: Trying to get property of non-object
  
  Filename: views/students.php
  
  Line Number: 32
  </code></pre>
  
  <p>This is how i am assigning User_id to session data.
  <strong>mycontroller.php</strong></p>
  
  <pre><code>                //[[session]]
  
  $data['students_data']= $this-&gt;loginmodel-&gt;student_profile($currentId);     
  
  
  $this-&gt;load-&gt;library('session');
     $this-&gt;session-&gt;set_userdata($currentId);
  </code></pre>