title: combining data from multiple lines into a single array
body: <p>I have some code which pulls from multiple tables of a MS SQL database, arranges the data and outputs an array, I then need to use that array to populate a worksheet telling someone what items are needed on a day to day basis. Right now the output looks like the below, where the fields are ID, Name, Date, number (they are asterisk deliminated because some names include commas).</p>
  
  <pre><code>74*xxxx*2017-06-04*1
  74*xxxx*2017-06-05*1
  74*xxxx*2017-06-06*2
  74*xxxx*2017-06-07*2
  74*xxxx*2017-06-08*2
  74*xxxx*2017-06-09*2
  74*xxxx*2017-06-10*2
  75*yyyy*2017-06-05*123
  75*yyyy*2017-06-06*111
  75*yyyy*2017-06-07*124
  75*yyyy*2017-06-08*107
  75*yyyy*2017-06-09*194
  75*yyyy*2017-06-10*195
  </code></pre>
  
  <p>I am trying to get them to merge them into a single value per ID so that I can print it out to a grid to look similar to:</p>
  
  <pre><code>| ID | NAME | 06-04 | 06-05 | 06-06 | 06-07 | 06-08 | 06-09 | 06-10 |
  | 74 | xxxx |   1   |   1   |   2   |   2   |   2   |   2   |   2   |
  | 75 | yyyy |   -   |  123  |  111  |  124  |  107  |  194  |  195  | 
  </code></pre>
  
  <p>my intent was to merge the array values into a single array with the dates as the keys, the (most recent) code I was trying is:</p>
  
  <pre><code>$schedule[] = $PID . "*" . $program . "*" .  $date . "*" .  $num;
  
  
  $grid = array();
  foreach ($schedule as $item ) {
  
      $ex = explode('*', $item);
      $grid[$ex[0]] = array(
          'name' =&gt; $ex[1],
          $ex[2] =&gt; $ex[3],
      );
  }
  </code></pre>
  
  <p>with the intent that that would merge them into a single array line to look like:</p>
  
  <pre><code>[74] =&gt; Array ( [name] =&gt; xxxx [2017-06-04] =&gt; 1 [2017-06-05] =&gt; 1 [2017-06-06] =&gt; 2 [2017-06-07] =&gt; 2 [2017-06-08] =&gt; 2 [2017-06-09] =&gt; 2 [2017-06-10] =&gt; 2)
  </code></pre>
  
  <p>after which I could just use it line by line with $grid[$i][1] etc to pull the value and print to each cell. I've tried other methods than the above, that is the only one I presently have the code snippet for and I've only been able to get it to keep the last value I add on a per ID basis. </p>
  
  <p>I'm certain there is a piece I am missing or simply not understanding, if anyone could offer some input it would be appreciated.</p>