title: PHP Sum Children in Array
body: <p>Hey I have an array where I would like to sum the values of the first-level children at various levels of the array.</p>
  
  <pre><code>&lt;?php
  $group = Array('Electronics' =&gt; Array(
                     '6 - Cameras &amp; Supplies' =&gt; Array(
                  'Cameras' =&gt; Array(
                      'Camcorders' =&gt; Array (
                          'Action Camcorders' =&gt; Array (
                              'total_ty_yest_sales' =&gt; 70.83,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 401.59,
                              'east_ty_yest_sales' =&gt; 65.20
                          ),
                          'Standard Camcorders' =&gt; Array (
                              'total_ty_yest_sales' =&gt; 96.09,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 96.09,
                              'east_ty_yest_sales' =&gt; 68.21
                          ),
                          'Surveillance' =&gt; Array(
                              'total_ty_yest_sales' =&gt; 84.00,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 84.00,
                              'east_ty_yest_sales' =&gt; 26.00
                          )
                      ),
                      'subCameras' =&gt; Array (
                          'Big Zoom' =&gt; Array(
                              'total_ty_yest_sales' =&gt; 31.66,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 13.68,
                              'east_ty_yest_sales' =&gt; 1.47
                          ),
                          'Pegged Cameras' =&gt; Array(
                              'total_ty_yest_sales' =&gt; 13.50,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 5.50,
                              'east_ty_yest_sales' =&gt; 5.00
                          ),
                          'Point-N-Shoot' =&gt; Array(
                              'total_ty_yest_sales' =&gt; 46.61,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 10.35,
                              'east_ty_yest_sales' =&gt; 4.06
                          ),
                          'Rugged Cameras' =&gt; Array(
                              'total_ty_yest_sales' =&gt; 87.04,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 87.04,
                              'east_ty_yest_sales' =&gt; 65.20
                          ),
                          'SLR' =&gt; Array(
                              'total_ty_yest_sales' =&gt; 50.19,
                              'total_wo_dotcom_ty_yest_sales' =&gt; 9.40,
                              'east_ty_yest_sales' =&gt; 1.37
                          )
                      )
              )   )   
          ));
          $totalSum = 0;
          echo "&lt;table&gt;\n
                  &lt;thead&gt;&lt;/thead&gt;\n
                  &lt;tbody&gt;\n";
  
          foreach($group as $gmm =&gt; $acctg_dept_nbrs) {
              echo "&lt;tr class=\"header\"&gt;\n
                      &lt;td&gt;" . $gmm . "&lt;/td&gt;\n";
  
              foreach ($acctg_dept_nbrs as $acctg_dept_nbr =&gt; $dept_catg_grp_descs) {
                  echo "&lt;tr class=\"header\"&gt;\n
                          &lt;td style=\"padding-left: 1em;\"&gt;" . $acctg_dept_nbr . "&lt;/td&gt;\n";
                              echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                              echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                              echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                  $total_acctg_dept_nbr = 0;
                  foreach($dept_catg_grp_descs as $dept_catg_grp_desc =&gt; $dept_category_descs) {
                      echo "&lt;tr class=\"header\"&gt;\n
                              &lt;td style=\"padding-left: 2em;\"&gt;" . $dept_catg_grp_desc . "&lt;/td&gt;\n";
                              echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                              echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                              echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                      $total_dept_catg_grp_desc = 0;
                      foreach($dept_category_descs as $dept_category_desc =&gt; $dept_subcatg_descs) {
                          echo "&lt;tr class=\"header\"&gt;\n
                                  &lt;td style=\"padding-left: 3em;\"&gt;" . $dept_category_desc . "&lt;/td&gt;\n";
                                  echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                                  echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
                                  echo "&lt;td style=\"width:100px;\"&gt;SUM&lt;/td&gt;\n";
  
                          foreach($dept_subcatg_descs as $dept_subcatg_desc =&gt; $values) {
                              echo "&lt;tr&gt;\n
                                      &lt;td style=\"padding-left: 4em;\"&gt;" . $dept_subcatg_desc . "&lt;/td&gt;\n";
  
                              $sum = $values['total_ty_yest_sales'];
                              echo "&lt;td style=\"width:100px;\"&gt;".$sum."&lt;/td&gt;\n";
                              $sum = $values['total_wo_dotcom_ty_yest_sales'];
                              echo "&lt;td style=\"width:100px;\"&gt;".$sum."&lt;/td&gt;\n";
                              $sum = $values['east_ty_yest_sales'];
                              echo "&lt;td style=\"width:100px;\"&gt;".$sum."&lt;/td&gt;\n";
  
                          }
                      }
                  }
              }
          }
  
  ?&gt;
  </code></pre>
  
  <p>I want to replace the "SUM"s in the output with the sum of the values of next level of indention.</p>