title: php a simple math task
body: <p>I have the most simple math problem to do that I just can't figure out (probably tired from working all day). It's simple, I loop through items and want to display the final price without the taxes and etc. The thing is that my math is correct, however when I am displaying the prices, all of the items have the same value (the value of the last item). I understand that the total variable is changing everytime I loop and at the last loop is displaying the last value. How to fix that?</p>
  
  <pre><code>public function getTotal($items)
  {
      $total;
      foreach($items as $item){
          $total = $item-&gt;getPrice() - $item-&gt;getDiscount() + $item-&gt;getValue();
      }
      return $total;
  }
  </code></pre>
  
  <p>It should display:</p>
  
  <pre><code>Item1: 154
  Item2: 77
  </code></pre>
  
  <p>It displays: </p>
  
  <pre><code>Item1:77
  Item2:77
  </code></pre>