Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Calculates the sum for a particular column in a multidimensional array.
- *
- * @param array $array
- * Input array.
- * @param string $key
- * The key for which sum should be calculated.
- */
- protected function sumArrayColumn(array $array, string $key) {
- return array_reduce($array, function ($reduced, $item) use ($key) {
- $reduced += (int) $item[$key];
- return $reduced;
- });
- }
Add Comment
Please, Sign In to add comment