title: Calculate foreach group in loop by 3 PHP
body: <p>Hope you are doing great!
  Please have an idea of ​​a comment grouped by 3, then the 4th to receive the value of the grouped in a month.
  This my dat below :</p>
  <pre><code>$salaries =
  [
      [
          'month'=&gt;'January',
          'salary'=&gt;200
      ],
      [
          'month'=&gt;'Februray',
          'salary'=&gt;300
      ],
      [
          'month'=&gt;'March',
          'salary'=&gt;400
      ],
      [
          'month'=&gt;'April',
          'salary'=&gt;500
      ],
      [
          'month'=&gt;'May',
          'salary'=&gt;600
      ],
      [
          'month'=&gt;'June',
          'salary'=&gt;700
      ],
      [
          'month'=&gt;'July',
          'salary'=&gt;800
      ],
      [
          'month'=&gt;'August',
          'salary'=&gt;900
      ],
      [
          'month'=&gt;'September',
          'salary'=&gt;1000
      ],
      [
          'month'=&gt;'October',
          'salary'=&gt;1100
      ],
      [
          'month'=&gt;'November',
          'salary'=&gt;130
      ],
      [
          'month'=&gt;'December',
          'salary'=&gt;1200
      ]
  ];
  </code></pre>
  <p>I tryed this code : <a href="https://stackoverflow.com/questions/50459746/sum-value-in-foreach-loop-every-3-time-looping">Sum Value in foreach loop every 3 time looping</a></p>
  <p>But i don't know specify the 4th with the sum, to loop in my view</p>
  <p>If possible, i want this :</p>
  <pre><code>Array
  (
      [0] =&gt; 
  [
  'month'=&gt;'April'
  'sum'=900
  ]
      [1] =&gt; 
  [
  'month'=&gt;'other month'
  'sum'=1800
  ]
      [2] =&gt; 
  [
  'month'=&gt;'other month'
  'sum'=2700
  ]
      [3] =&gt; 
  [
  'month'=&gt;'other month'
  'sum'=2430
  ]
  )
  </code></pre>
  <p>I try this code :</p>
  <pre class="lang-php prettyprint-override"><code>$groupSum = []; 
  foreach (array_chunk($salaries , 3) as $key =&gt; $value) { 
      $groupSum[] = array_reduce($value, function ($sum, $item) { 
          $sum += $item['salary']; return $sum; 
      }); 
  }
  </code></pre>
  <p>And the result is :</p>
  <pre><code>Array ( 
      [0] =&gt; 900
      [1] =&gt; 1800
      [2] =&gt; 2700
      [3] =&gt; 2430
  )
  </code></pre>