title: How to store array in CodeIgniter sessions?
body: <p>I am calling a controller with method <code>setActiveId</code> and store 1 array in session and display after storing by using <code>var_dump($this-&gt;session-&gt;all_userdata())</code> it shows perfectly but in same controller when I print the session in other method say <code>checkinkingPermission</code> then the array in session is empty.</p>
  
  <p>Now I repeat all steps with one additional step.</p>
  
  <p>I did store array in session like before and after storing I store one dummy variable in session like this,</p>
  
  <pre><code>$this-&gt;session-&gt;set_userdata('dummy','tesing');
  </code></pre>
  
  <p>and again print using <code>var_dump($this-&gt;session-&gt;all_userdata())</code> it display all session with array and last dummy variable and when check in <code>checkinkingPermission</code> then array in session and dummy variable is shown perfectly (it solves my problem but its rough solution).</p>
  
  <p>I want to know did anything  miss or what problem is there that array not save in first scenario (also array is not greater then 4Kb (CI Session limit)).</p>
  
  <p><strong>Update</strong></p>
  
  <p>Method from model named connections_model</p>
  
  <pre><code>public function setActiveFriend($id) {
      $this-&gt;load-&gt;model('friend_model');
      $this-&gt;session-&gt;set_userdata('AF',$id);
      if($id==$this-&gt;session-&gt;userdata('userid'))
      {
          $this-&gt;session-&gt;set_userdata('MEOWN',1);
      }
      else
      {
          $this-&gt;session-&gt;set_userdata('MEOWN',0);
      }
      $this-&gt;friend_model-&gt;setFP($id); // Calls Here a method that is defined in another model
  }
  </code></pre>
  
  <p>Another method that defined in friend_model</p>
  
  <pre><code>public function setFriendPermissions($id) {
  
      $this-&gt;session-&gt;set_userdata('CFP',array());
      $this-&gt;db-&gt;where('user_id',$id);
      $locs = $this-&gt;db-&gt;get('friend_p')-&gt;result_array();
  
      if(is_array($locs))
      {
          foreach($locs as $loc)
          {
              array_push($this-&gt;session-&gt;userdata['CP'],$loc['perm_id']);
          }
      }
      $this-&gt;session-&gt;set_userdata('dummy','tesing'); // Important Line
  }
  </code></pre>
  
  <p>In above method I set values in session array if I want to see session values in same method  then its set and viewed but the array is empty if I print session in any method of connections_model file.</p>
  
  <p><strong>Important</strong>
  If I wrote this line <code>$this-&gt;session-&gt;set_userdata('dummy','tesing');</code> then session array save and viewd in all methods and if I don't write that line session array is empty.</p>