title: How to add $_POST values in a multi-dimensional array (PHP)?
body: <p>I know there may be sources for this out there but I'v tried everything and I'm still not getting the proper solution. That why I'm asking for you help out here.</p>
  
  <p>I have a $_POST array and I want to put values in a an array. Here is the final out I want:</p>
  
  <pre><code>$response = [
               ['category' =&gt; 2, 'value' =&gt; "june"],
               ['category' =&gt; 5, 'value' =&gt; "may"],
               ['category' =&gt; 8, 'value' =&gt; "april"]
              ]
  </code></pre>
  
  <p>Here is the catch,the $_POST contains a value of an integer with a space in between and then a string eg '2 june', '5 may' etc</p>
  
  <p>When I get this value, I split it using explode then I try to add the individual values into the response array. This is only adding just one result.</p>
  
  <p>What I tried:</p>
  
  <pre><code>$response = [];
  
  foreach ($_POST as $key =&gt; $value) {
  
      $split = explode(" ", $value);
      $result = ['category' =&gt; $split[0], 'value' =&gt; $split[1]];
  
      $response[] = $result;
  
  }
  </code></pre>
  
  <p>for some reason, the results are not as suggested above. Any ideas and suggestion will be appreciated.</p>