positive_sum()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
You get an array of numbers, return the sum of all of the positives ones.
4
5
Example [1,-4,7,12] => 1 + 7 + 12 = 20
6
7
Note: if there is nothing to sum, the sum is default to 0.
8
*/
9
10
function positive_sum($arr)
11
{
12
    $sum = 0;
13
    foreach ($arr as $value) {
14
        if ($value > 0) {
15
            $sum += $value;
16
        }
17
    }
18
    return $sum;
19
}
20