title: Sum all key/value pairs within a multidimensional PHP array
body: <p>I am developing a small application that pulls recent game data for players, and I want to display a total amount of the stats (goals, assists, plusminus, shots, pim) across all of the games by each player id.</p>
  <p>This is an example of what my array looks like for three games that were pulled. The top level is the game id, followed by the player id's that were involved in that game. The layer under each player id are the stats that I want to total up in my output.</p>
  <p><a href="https://i.stack.imgur.com/B6Qkb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6Qkb.png" alt="Test" /></a></p>
  <p>I have attempted to loop through each game and player with the following code, but it only appears to pull the non-totaled stats from the first game.</p>
  <pre><code>foreach ($results as $result) {
    foreach ($result as $index =&gt; $value) {
      $sumArray[$index] = (isset($sumArray[$index]) ? $sumArray[$index] + $value : $value);
    }
  }
  </code></pre>
  <p>Would anyone be able offer some guidance on how I can loop through and total up the player stats for each player id occurrence? Any help would be appreciated. Thank you!</p>