title: Adding subtotal PHP foreach loop
body: <p>i have been stuck on this and reaching for help. I believe i need to add an additional loop, or counter, i just don't know when and where :)</p>
  
  <p>I am trying to accomplish a subtotal of cash, CC and total for each employeeid.</p>
  
  <pre><code>foreach ($weekly as $week){
          $week_array = getStartAndEndDate($week['week'],$week['year']);
          if(isset($week['employeeid'])){
                  echo "&lt;TR&gt;";
                  if($week['employeeid']!=$tmpEmp){
                          echo "&lt;TD colspan='5'&gt;&lt;strong&gt;".$week['employeeid']."&lt;/strong&gt;&lt;/TD&gt;&lt;/TR&gt;
                          &lt;TR&gt;&lt;TD&gt;".$week_array['week_start']."&lt;/TD&gt;";
                          $tmpEmp = $week['employeeid'];
                  }
                  else {
                          echo "&lt;TD&gt;".$week_array['week_start']."&lt;/TD&gt;";
                          $tmpEmp = $week['employeeid'];
                  }      
                  echo
                  "&lt;TD&gt;".$week['CC']."&lt;/TD&gt;
                  &lt;TD&gt;".$week['Cash']."&lt;/TD&gt;
                  &lt;TD&gt;".$week['total']."&lt;/TD&gt;
                  &lt;TD&gt;&lt;a href=employee.php?week=".$week['week']."&amp;year=".$week['year']."&gt;Report&lt;/a&gt;&lt;/TD&gt;
                  &lt;/TR&gt;";
  
  
                  $tmpCC += $week['CC'];
                  $tmpCash += $week['Cash'];
                  $tmpTotal += $week['total'];
  
  
          }      
  
  }
                  echo "&lt;TR&gt;&lt;TD&gt;&lt;strong&gt;Group Total&lt;/strong&gt;&lt;/TD&gt;
                  &lt;TD&gt;".$tmpCC."&lt;/TD&gt;
                  &lt;TD&gt;".$tmpCash."&lt;/TD&gt;
                  &lt;TD&gt;".$tmpTotal."&lt;/TD&gt;
                  &lt;TD&gt;&lt;/TD&gt;
                  &lt;/TR&gt;
                   &lt;/TABLE&gt;&lt;HR /&gt;";
  </code></pre>
  
  <p>---Current RESULT---</p>
  
  <pre><code>Employee        CC      Cash    Total   View Report
  1
  2014-10-20      0.00    271.61  271.61  Report
  2
  2014-10-06      75.38   0.00    75.38   Report
  2014-10-13      0.00    472.66  472.66  Report
  4
  2014-09-29      219.39  0.00    219.39  Report
  5
  2014-09-29      0.00    464.40  464.40  Report
  2014-10-20      390.37  0.00    390.37  Report
  Group Total     685.14  1208.67 1893.81
  </code></pre>
  
  <p>---Wanted RESULT---</p>
  
  <pre><code>Employee        CC      Cash    Total   View Report
  1
  2014-10-20      0.00    271.61  271.61  Report
  Subtotal        XX      XX      XX     
  2
  2014-10-06      75.38   0.00    75.38   Report
  2014-10-13      0.00    472.66  472.66  Report
  Subtotal        XX      XX      XX
  4
  2014-09-29      219.39  0.00    219.39  Report
  Subtotal        XX      XX      XX
  5
  2014-09-29      0.00    464.40  464.40  Report
  2014-10-20      390.37  0.00    390.37  Report
  Subtotal        XX      XX      XX
  Group Total     685.14  1208.67 1893.81
  </code></pre>