title: PHP multidimensional associative array
body: <p>I am new to php &amp; I'm not sure that this can be done, but I am hoping that someone knows how to. I've collected all the data that I need to submit but now I need to reformat it before I can json_encode to send to the database. </p>
  
  <p>Basically, I have 1 parent array($data) containing 3 sub-arrays ($hours, $WId, $Pid). I need to create associative arrays for each index position &amp; join them together. </p>
  
  <p>Here is my parent array: </p>
  
  <pre><code>$data = array(
  'hours' =&gt; array(),
  'wId' =&gt; array(),
  'phaseId' =&gt; array(),
  );
  </code></pre>
  
  <p>Here is what currently returns when I print_r each of these arrays: </p>
  
  <pre><code>Array ( [hours] =&gt; Array ( [0] =&gt; 0.5 [1] =&gt; 1 [2] =&gt; 2 ) ) 
  Array ( [wId] =&gt; Array ( [0] =&gt; 10, [1] =&gt; 9, [2] =&gt; 8, ) ) 
  Array ( [phaseId] =&gt; Array ( [0] =&gt; 20, [1] =&gt; 20, [2] =&gt; 19, ) ) 
  </code></pre>
  
  <p>I need to take these "vertical" arrays &amp; turn them in to "horizontal" arrays per index, using thearray name as the $key &amp; the value for that index as $value. Here is what I need to return.... (Syntax is probably wrong but you can get the idea.) </p>
  
  <pre><code>Array[1] ("hours" =&gt; 0.5, "wId" =&gt; 10, "phaseId" =&gt; 20)
  Array[2] ("hours" =&gt; 1, "wId" =&gt; 9, "phaseId" =&gt; 20)
  Array[3] ("hours" =&gt; 2, "wId" =&gt; 8, "phaseId" =&gt; 19)
  </code></pre>
  
  <p>Is there a function that will allow me to do this easily? I saw how to join &amp; merge them together but not sure how to set the array name (hours, etc) as the $key &amp; the value for each index as $value. I need to loop it too because the length of the arrays will vary. (But they will always the same length as each other, so index should still work as what needs to be collected.) </p>
  
  <p>Any suggestions would be greatly appreciated :) </p>