title: Php apply discount to multiple products evenly
body: <p>Im trying to figure something out. I want to apply coupon/discount amount to multiple products evenly.</p>
  
  <p>For example if I have an array with 3 items</p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [id] =&gt; 1
              [price] =&gt; 10.00
          )
  
      [1] =&gt; stdClass Object
          (
              [id] =&gt; 2
              [price] =&gt; 20.00
          )
  
      [2] =&gt; stdClass Object
          (
              [id] =&gt; 3
              [price] =&gt; 30.00
          )
  
  )
  </code></pre>
  
  <p>my coupon vale is 10 $ off</p>
  
  <p>and I have tried this:</p>
  
  <pre><code>foreach ($array as $row) {
     $data['price'] = ($row-&gt;price - 10 / 3) * 100
  }
  </code></pre>
  
  <p>So basically I want to deduct from each item price proportionally total of 10 and end up with something like:</p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [id] =&gt; 1
              [price] =&gt; 7.50
          )
  
      [1] =&gt; stdClass Object
          (
              [id] =&gt; 2
              [price] =&gt; 17.50
          )
  
      [2] =&gt; stdClass Object
          (
              [id] =&gt; 3
              [price] =&gt; 25.00
          )
  
  )
  </code></pre>
  
  <p>where total price sum is 50 instead original of 60</p>