title: How to convert flat PHP array to indexed array
body: <p>I have the following array:</p>
  
  <pre><code>'values' =&gt; [
          'protein_question_0_typing_method' =&gt; '38'
          'protein_question_0_amount_1' =&gt; '1'
          'protein_question_0_amount_2' =&gt; '2'
          'protein_question_0_units_of_measurement' =&gt; '17'
          'protein_question_1_typing_method' =&gt; '39'
          'protein_question_1_amount_1' =&gt; '2'
          'protein_question_1_amount_2' =&gt; '2'
          'protein_question_1_units_of_measurement' =&gt; '17'
          'protein_question_2_typing_method' =&gt; '42'
          'protein_question_2_amount_1' =&gt; '2'
          'protein_question_2_amount_2' =&gt; '2'
          'protein_question_2_units_of_measurement' =&gt; '17'
          'distributionId' =&gt; '21'
      ]
  </code></pre>
  
  <p>How would I convert into a structure like this?</p>
  
  <pre><code>'values' =&gt; [
           0 =&gt; [
            'protein_question_typing_method' =&gt; '38',
            'protein_question_amount_1' =&gt; '1',
            'protein_question_amount_2' =&gt; '2'
           ],
           1 =&gt; [
            'protein_question_typing_method' =&gt; '42',
            'protein_question_amount_1' =&gt; '1',
            'protein_question_amount_2' =&gt; '2'
           ],
           ...
  
          'distributionId' =&gt; '21'
      ]
  </code></pre>
  
  <p>This is what I've tried:</p>
  
  <pre><code>       $params = \Yii::$app-&gt;request-&gt;post();
  
          $length = count($params['values']);
          for($i = 0; $i &lt; $length; $i++) {
  
              if(!empty($params['values']['protein_question_' . $i . '_typing_method'])) {
                  echo $params['values']['protein_question_' . $i . '_typing_method'] . "&lt;br /&gt;&lt;hr /&gt;";
              }
  
          }
  </code></pre>
  
  <p><strong>The above code just prints the data, the reason I need it in the chunked format is because each chunk will be saved as a new model record in the DB.</strong></p>
  
  <p>So basically just need to convert it to an index array, anyone know the easiest way to do this as looping over the first array would be complicated?</p>
  
  <p>Thanks</p>