title: Grouping and adding values multidimensional array
body: <h2>Code</h2>
  
  <pre><code>foreach ($summary as $split) {
      if (isset($split['currency'])) {
          if (!isset($result[$split['currency']]) {
              $result[$split['currency']] = [
                  'duration' =&gt; 0,
                  'cost' =&gt; 0
              ];
          }
          $result[$split['currency']]['employee'] = $split['employee'];
          $result[$split['currency']]['duration'] += $split['duration'];
          $result[$split['currency']]['cost'] += $split['cost'];
      } else {
          $result[0]['employee'] = $split['employee'];
          $result[0]['duration'] += $split['duration'];
          $result[0]['cost'] += $split['cost'];
      }
  }
  </code></pre>
  
  <p>My array looks like this</p>
  
  <pre><code>$summary = Array
  (
  [0] =&gt; Array
     (
      [employee] =&gt; John
      [currency] =&gt; SGD
      [duration] =&gt; 8.00
      [cost] =&gt; 228.57
  )
  
  [1] =&gt; Array
     (
      [employee] =&gt; Fil
      [currency] =&gt; SGD
      [duration] =&gt; 8.00
      [cost] =&gt; 228.57
   )
  
  [2] =&gt; Array
  (
      [employee] =&gt; John
      [currency] =&gt; 
      [duration] =&gt; 8.00
      [cost] =&gt; 
  )
  
  [3] =&gt; Array
  (
      [employee] =&gt; John
      [currency] =&gt; MYR
      [duration] =&gt; 12.00
      [cost] =&gt; 342.86
  )
  
  [4] =&gt; Array
  (
      [employee] =&gt; Sam
      [currency] =&gt; SGD
      [duration] =&gt; 8.00
      [cost] =&gt; 228.57
  )
  
  [5] =&gt; Array
  (
      [employee] =&gt; Fil
      [currency] =&gt; MYR
      [duration] =&gt; 12.00
      [cost] =&gt; 342.86
  )
  </code></pre>
  
  <p>I want to group the above array by employee and currency. What I require is similar to <a href="https://stackoverflow.com/questions/38607559/undefined-index-when-grouping-and-sum-values-in-multidimensional-array">Stackoverflow</a></p>
  
  <p>but in this grouping is done for currency only so in the output array there will be 3 inner array only. </p>
  
  <p><strong>I want to group the array such that the result will group first employee and then currency. So there will be 3 inner array for each employee</strong></p>