title: sum all value in foreach loop php
body: <pre><code> &lt;?php  foreach((array)$query as $row):?&gt;
    &lt;td&gt;&lt;?php echo $row-&gt;date ?&gt;&lt;/td&gt;
    &lt;td&gt;&lt;?php echo $row-&gt;cost ?&gt;&lt;/td&gt;
    &lt;?php endforeach ;?&gt;
  </code></pre>
  
  <p>I want to sum all values in <code>$row-&gt;cost</code> when <code>$row-&gt;date=02-01-2016</code>, like this in a table
  <a href="https://i.stack.imgur.com/MM4LZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MM4LZ.png" alt="enter image description here"></a></p>
  
  <p>Thanks.</p>