Guest User

Untitled

a guest
Oct 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Calculates the sum for a particular column in a multidimensional array.
  5. *
  6. * @param array $array
  7. * Input array.
  8. * @param string $key
  9. * The key for which sum should be calculated.
  10. */
  11. protected function sumArrayColumn(array $array, string $key) {
  12. return array_reduce($array, function ($reduced, $item) use ($key) {
  13. $reduced += (int) $item[$key];
  14. return $reduced;
  15. });
  16. }
Add Comment
Please, Sign In to add comment