title: Loop through array and populate table and prevent new rows, values need to be in one row?
body: <p>I have a array of column headers which are the table column headers. Based on these column values I want to loop through an multiple associative array and display the text where period_id equals the column header id.</p>
  
  <p>I have the following function and the problem is every found value comes on a new <code>&lt;tr&gt;</code>:</p>
  
  <pre><code>     P1 | P2 | P3 | P4 | P5 | P6 | P7 | P8 | P9 | P10 | P11
  
     |    |    | msg 1|    | msg2   |    |    |  msg3  |   |  
  </code></pre>
  
  <p>and not</p>
  
  <pre><code>  |    |    | msg 1 |    |    |    |    |    |   |  
    |    |    |       |    | msg2   |    |    |    |    | | 
    |    |    |       |    |    |    |    |    |  msg3  | | 
  </code></pre>
  
  <p>Hera are Both arrays and code which outputs each on a sperate row. I guess i am using a foreach too many. (array_map?? or list?)</p>
  
  <pre><code>  /***
   * Populate Table
   */
  
  $colHeads = [
     [
              'period_id'=&gt; 14,
              'period' =&gt; 'p1',
         ],
     [
              'period_id'=&gt; 1,
              'period' =&gt; 'p2',
  
         ],
     [
              'period_id'=&gt; 2,
              'period' =&gt; 'p2',
  
         ],
     [
              'period_id'=&gt; 4,
              'period' =&gt; 'p3',
  
         ],
     [
              'period_id'=&gt; 5,
              'period' =&gt; 'p5',
  
         ],
     [
              'period_id'=&gt; 6,
              'period' =&gt; 'p6',
         ],
     [
              'period_id'=&gt; 7,
              'period' =&gt; 'p7',
         ],
     [
              'period_id'=&gt; 8,
              'period' =&gt; 'p8',
  
         ],
     [
              'period_id'=&gt; 9,
              'period' =&gt; 'p9',
  
         ],
     [
              'period_id'=&gt; 10,
              'period' =&gt; 'p10',
  
         ],
     [
              'period_id'=&gt; 11,
              'period' =&gt; 'p11',
         ],
  
  ];
  
  
  $dailyFeedbacks = [
      [
          'date' =&gt; '2017-01-18',
          'period_id' =&gt; 4,
          'feedback_score' =&gt; 4,
          'feeback_notes' =&gt; 'test is pos feedack',
      ],
      [
          'date' =&gt; '2017-01-18',
          'period_id' =&gt; 6,
          'feedback_score' =&gt; 2,
          'feeback_notes' =&gt; 'test is asdf feedack',
      ],
      [
          'date' =&gt; '2017-01-18',
          'period_id' =&gt; 10,
          'feedback_score' =&gt; 2,
          'feeback_notes' =&gt; 'test is asdf feedack',
      ], 
      // Neg feedback on seperat row???
   [
          'date' =&gt; '2017-01-18',
          'period_id' =&gt; 8,
          'feedback_score' =&gt; -3,// Neg feedback
          'feeback_notes' =&gt; 'test is neg feedack',
      ], 
  ];
  
  
      $tableRow ='&lt;table&gt;';
      $tableRow .= '&lt;tr&gt;&lt;td&gt;Feedback&lt;/td&gt;';
  
      $i = 0;
      foreach ($colHeads as $headCol) {
       foreach($dailyFeedbacks as $dailyFeedback) {
          if ($i == 11) {
                      $i = 0;
                  }
               $periodHead = $headCol['period_id'];
              if ($dailyFeedback['period_id']==$periodHead ) {
                  $tableRow .= '&lt;td&gt;'.$dailyFeedback['feeback_notes'].'&lt;/td&gt;';
              }  else {
                  $tableRow .= '&lt;td&gt;&amp;nbsp;&lt;/td&gt;';
              }
              $i++;
                  if($i == 11){
                      $tableRow .= '&lt;/tr&gt;';
                  }
          }   
      }
      $tableRow .= '&lt;/table&gt;';
      echo $tableRow;
  </code></pre>