Question: I have problem with my arrays and `sum_array()` function.

This code is not working properly. I have commented what it should print.

```
$teams[1]['AREA I']['blue'] = 30;
$teams[1]['AREA I']['green'] = 25;
$teams[1]['AREA II']['blue'] = 15;
$teams[2]['AREA I']['blue'] = 40;

echo array_sum($teams[1]); // 30+25+15=70
echo array_sum($teams[1]['AREA I']); // 30+25=55
echo array_sum($teams[1]['AREA I']['blue']); // 30

```

I think I'm using arrays wrong way, but I'm new into this and some consultation is appreciated.

Thanks in advance.

Answer: 
array\_sum — Calculate the sum of values in an array. As your array is multi dimensional so you should loop it. Try as below :

```
$teams[1]['AREA I']['blue'] = 30;
$teams[1]['AREA I']['green'] = 25;
$teams[1]['AREA II']['blue'] = 15;
$teams[2]['AREA I']['blue'] = 40;
$sum = 0;

foreach($teams as $num => $values) {
    if(is_array($values))
    {
        foreach($values as $num1 => $values1) {
            $sum += array_sum($values1);
        }
    }
}
echo $sum;

```
`array_sum()` expects an array to be passed as a parameter, so if you run your current code with `error_reporting` switched on it will throw back the following:

> 
> E\_WARNING : type 2 -- array\_sum() expects parameter 1 to be array, integer given -- at line 10
> 
> 
> 

You are passing in the number 30 as an integer to a function that is expecting an array, so it errors and doesn't return what you're expecting.

You can read up on the function in the PHP Manual: 

<http://php.net/manual/en/function.array-sum.php>

You may also find the error reporting page helpful:

<http://php.net/manual/en/function.error-reporting.php>