From 42c403a60c653237093b6c809410727e6b90b5fc Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 14 Sep 2016 18:06:26 +0200 Subject: [PATCH] Added filtered array sum Implement more like this for key value pairs. --- Utils/ArrayUtils.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 3a752229a..0b52e44cb 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -245,4 +245,20 @@ class ArrayUtils return trim($args[$key + 1], '" '); } + + public static function arraySum(array $array, int $start = 0, int $count = 0) + { + $count = $count === 0 ? count($array) : $count; + $sum = 0.0; + + for($i = $start; $i <= $count-1; $i++) { + if(!isset($array[$i])) { + continue; + } + + $sum += $array[$i]; + } + + return $sum; + } }