title: Average result of multidimensional array in PHP
body: <p>This is a question for all the array specialists out there. I have an multi dimension array with a result as number (can be 0,1 or 2) and need the average for each grouped by parent.</p>
  
  <p>In the example below the calculation would be:</p>
  
  <p>subentry1_sub1 = 2 + 2 = 4 (4/2=<strong>2</strong>)</p>
  
  <p>subentry1_sub2 = 1 + 1 = 2 (2/2=<strong>1</strong>)</p>
  
  <p>So what I try to archive in PHP is the following result:</p>
  
  <p><strong>subentry1_sub1 average = 2</strong></p>
  
  <p><strong>subentry1_sub2 average = 1</strong></p>
  
  <p>...</p>
  
  <p>I already tried some solutions from similar questions. But with all the recursive functions I didn't managed to get it aggregated by the last child name (e.g. subentry1_sub1).</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>subentry1_sub1 is 2 + 2 because its two times in the array</p>
  
  <p>[entry1] => [subentry1] => [subentry1_sub1] => result</p>
  
  <p>[entry2] => [subentry1] => [subentry1_sub1] => result</p>
  
  <pre><code>Array
  (
      [entry1] =&gt; Array
          (
              [subentry1] =&gt; Array
                  (
                      [subentry1_sub1] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 2
                          )
  
                      [subentry1_sub2] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 1
                          )
  
                  )
  
              [subentry2] =&gt; Array
                  (
                      [subentry2_sub1] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 1
                          )
  
                      [subentry2_sub2] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 1
                          )
  
                  )
  
          )
  
      [entry2] =&gt; Array
          (
              [subentry1] =&gt; Array
                  (
                      [subentry1_sub1] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 2
                          )
  
                      [subentry1_sub2] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 1
                          )
  
                  )
  
              [subentry2] =&gt; Array
                  (
                      [subentry2_sub1] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 1
                          )
  
                      [subentry2_sub2] =&gt; Array
                          (
                              [value] =&gt; abc
                              [result] =&gt; 1
                          )
  
                  )
  
          )        
  )
  </code></pre>