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;

```
As array\_sum() works on single dimensional array, it will not work for your first and third case. It will only work for your second case which is as follows.

> 
> echo array\_sum($teams[1]['AREA I']);
> 
> 
>