title: Store $_POST in Yii2 session
body: <p>I'm having a little trouble with my quiz form. I'm using a page to show a single question that a user answers, from there I was hoping to save the question id and option id (My form is multiple choice, i set the options).</p>
  
  <p>My HTML looks like this:</p>
  
  <pre><code>&lt;input type="radio" name="question[3]" value="4"&gt;My Answer
  </code></pre>
  
  <p>When the form is posted I am doing this</p>
  
  <pre><code>if(isset(Yii::$app-&gt;session['question'])){
  
                  // Get posted array
                  $question = $_POST['question'];
                  Yii::$app-&gt;session['question'] = $question;
                  print_r(Yii::$app-&gt;session['question']);
              }
  </code></pre>
  
  <p>So it's saved into my session as:</p>
  
  <pre><code>Array
  (
  [3] =&gt; 4
  )
  </code></pre>
  
  <p>Which is fine, the problem I'm finding is trying to save the next question without overwriting the previous [question_id] => [option_id].</p>
  
  <p>I understand why the following code just overwrites the existing the session['question'] variable. But I'm struggling to be able to save each question and answer array to my variable.</p>
  
  <p>I have tried <code>Yii::$app-&gt;session['question'][$i] = $question;</code> and get <code>Indirect modification of overloaded element of yii\web\Session has no effect</code></p>
  
  <p>I've also tried <code>array_push</code> and <code>array_merge</code> to try and combine the previous array of question and chosen option, but have had no luck either. What am I doing wrong here please?</p>