title: How to set an array in session in codeigniter?
body: <p>I am little bit struggling in setting array in session.</p>
  
  <p>Here is my code:-</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>function taketest(){
      $this-&gt;load-&gt;model('', '');
      $questions_for_test = $this-&gt;session-&gt;userdata('questions_for_test');
      $difficulty_level = $this-&gt;session-&gt;userdata('difficulty_level');
      $question_id = $this-&gt;session-&gt;userdata('question_id');
      if($question_id==""){
          $question_id = $this-&gt;myjcat-&gt;returnRandomQuestion($questions_for_test,$difficulty_level);
          $this-&gt;session-&gt;set_userdata('question_id',$question_id);
      }
      $question_details = $this-&gt;myjcat-&gt;getQuestion($question_id);
  }
  </code></pre>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>function returnRandomQuestion($questions_for_test, $difficulty_level){
      $question_id = array_rand($questions_for_test[$difficulty_level], 1);
      $used_question=array();
      $used_questions=$questions_for_test[$difficulty_level][$question_id];
      $this-&gt;session-&gt;set_userdata('used_questions',$used_questions);
      return $questions_for_test[$difficulty_level][$question_id];
  }
  </code></pre>
  
  <p>But when I call:</p>
  
  <pre><code>$used_questions = $this-&gt;session-&gt;userdata('used_questions');
  </code></pre>
  
  <p>in controller
  in the controller it will not return me an array.It gives me last value stored in it.</p>