title: php adding values in same foreach
body: <p>I am trying to add up all the books sold quantities, for example Book A sold 55, Book B sold 9, Book A 65, Book B sold 20. Book A = 120 and Book B = 29.</p>
  
  <p>And as you can see i need to add up the numeral values per book. I just not sure how to add up values.</p>
  
  <p>My array looks like this:</p>
  
  <pre><code>Array
  (
  [Visual Flight Guide] =&gt; Array
      (
          [0] =&gt; 1
          [30] =&gt; 5
          [39] =&gt; 3
          [69] =&gt; 6
          [118] =&gt; 10
      )
  
  [Flight Radio for Pilots  VFR Operations] =&gt; Array
      (
          [1] =&gt; 1
          [5] =&gt; 1
          [17] =&gt; 5
          [46] =&gt; 1
          [53] =&gt; 5
          [120] =&gt; 4
      )
  
  [ATC Pilots Logbook] =&gt; Array
      (
          [2] =&gt; 1
          [3] =&gt; 1
          [20] =&gt; 30
          [27] =&gt; 26
          [28] =&gt; 1
          [40] =&gt; 8
          [54] =&gt; 52
          [66] =&gt; 30
          [78] =&gt; 52
          [121] =&gt; 30
      )
  
  [Aerobatics  Principles and Practice] =&gt; Array
      (
          [4] =&gt; 1
      )
  
  [Instrument Flight Guide] =&gt; Array
      (
          [6] =&gt; 5
          [18] =&gt; 1
          [32] =&gt; 1
          [41] =&gt; 6
          [56] =&gt; 5
          [70] =&gt; 6
          [108] =&gt; 8
          [130] =&gt; 5
      )
  
  [Command Instrument Rating] =&gt; Array
      (
          [7] =&gt; 10
          [16] =&gt; 1
          [35] =&gt; 1
          [57] =&gt; 5
          [67] =&gt; 6
          [93] =&gt; 3
          [113] =&gt; 2
      )
  
  [Student Pilot Kit] =&gt; Array
      (
          [8] =&gt; 5
          [13] =&gt; 4
          [44] =&gt; 1
          [51] =&gt; 9
          [61] =&gt; 12
          [80] =&gt; 1
          [102] =&gt; 5
          [117] =&gt; 2
          [134] =&gt; 1
      )
  
  [Basic Aeronautical Knowledge] =&gt; Array
      (
          [9] =&gt; 10
          [29] =&gt; 5
          [52] =&gt; 5
          [63] =&gt; 6
          [79] =&gt; 20
          [94] =&gt; 1
          [106] =&gt; 1
          [110] =&gt; 12
          [119] =&gt; 4
      )
  
  [Human Factors] =&gt; Array
      (
          [10] =&gt; 10
          [22] =&gt; 1
          [45] =&gt; 1
          [83] =&gt; 6
          [122] =&gt; 3
      )
  
  [ATC Rotating Plotter] =&gt; Array
      (
          [11] =&gt; 4
      )
  
  [ATC Protractor] =&gt; Array
      (
          [12] =&gt; 5
          [42] =&gt; 12
          [60] =&gt; 10
          [74] =&gt; 30
          [81] =&gt; 25
      )
  
  [180NM Scale Rule] =&gt; Array
      (
          [14] =&gt; 4
          [43] =&gt; 12
          [73] =&gt; 30
          [82] =&gt; 25
      )
  
  [Seven Volume PPLCPL Kit] =&gt; Array
      (
          [15] =&gt; 4
          [19] =&gt; 1
          [31] =&gt; 1
          [62] =&gt; 6
          [77] =&gt; 1
          [100] =&gt; 3
          [128] =&gt; 3
      )
  
  [Fake Item] =&gt; Array
      (
          [21] =&gt; 1
      )
  
  [Flight Rules and Air Law] =&gt; Array
      (
          [23] =&gt; 1
          [87] =&gt; 7
          [97] =&gt; 1
          [127] =&gt; 5
      )
  
  [Aircraft Operation Performance and Planning] =&gt; Array
      (
          [24] =&gt; 1
          [88] =&gt; 4
          [95] =&gt; 1
          [112] =&gt; 6
          [133] =&gt; 1
      )
  
  [Aerodynamics] =&gt; Array
      (
          [25] =&gt; 1
          [91] =&gt; 1
          [101] =&gt; 1
          [104] =&gt; 1
          [124] =&gt; 3
      )
  
  [Aircraft General Knowledge] =&gt; Array
      (
          [26] =&gt; 1
          [84] =&gt; 5
          [92] =&gt; 1
          [99] =&gt; 1
          [105] =&gt; 1
          [123] =&gt; 3
      )
  
  [Human Being Pilot] =&gt; Array
      (
          [33] =&gt; 1
          [68] =&gt; 3
          [109] =&gt; 16
      )
  
  [Flight Rules and Air Law for the Air Transport Pilot] =&gt; Array
      (
          [34] =&gt; 1
          [55] =&gt; 3
          [65] =&gt; 3
          [89] =&gt; 1
          [129] =&gt; 2
      )
  
  [Aerodynamics Engines  Airframe Systems for the Air Transport Pilot] =&gt; Array
      (
          [36] =&gt; 1
      )
  
  [Aeroplane Performance Planning  Loading for the Air Transport Pilot] =&gt; Array
      (
          [37] =&gt; 1
          [98] =&gt; 1
      )
  
  [Avionics and Flight Management Systems for the Air Transport Pilot] =&gt; Array
      (
          [38] =&gt; 1
      )
  
  [The Flying Training Manual] =&gt; Array
      (
          [47] =&gt; 1
          [48] =&gt; 1
          [103] =&gt; 6
          [107] =&gt; 10
          [116] =&gt; 2
      )
  
  [In Safe Hands] =&gt; Array
      (
          [49] =&gt; 3
      )
  
  [Helicopter Trial Instructional Flight] =&gt; Array
      (
          [50] =&gt; 3
      )
  
  [Flight at Lower Levels  Safety in the Circuit] =&gt; Array
      (
          [58] =&gt; 3
      )
  
  [Night Flight] =&gt; Array
      (
          [59] =&gt; 3
          [75] =&gt; 4
          [114] =&gt; 1
          [132] =&gt; 1
      )
  
  [Meteorology] =&gt; Array
      (
          [64] =&gt; 3
          [85] =&gt; 7
          [111] =&gt; 6
          [125] =&gt; 3
      )
  
  [80NM Scale Rule] =&gt; Array
      (
          [71] =&gt; 10
      )
  
  [120NM Scale Rule] =&gt; Array
      (
          [72] =&gt; 10
      )
  
  [MultiEngine Piston] =&gt; Array
      (
          [76] =&gt; 2
      )
  
  [Navigation] =&gt; Array
      (
          [86] =&gt; 5
          [96] =&gt; 2
          [126] =&gt; 3
      )
  
  [Three Points  Flying a Tailwheel Aircraft] =&gt; Array
      (
          [90] =&gt; 1
      )
  
  [Pilots Index] =&gt; Array
      (
          [115] =&gt; 1
          [131] =&gt; 5
      )
  
  )
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>$stock_taken = array();
      $i = 0; 
      foreach($stock_take as $stock){
          $stock_taken[$stock-&gt;name][$i] = $stock-&gt;qty;
          $i++;
      }
  </code></pre>