Have you defined $sum2[$stat_name]
as 0
? If not, you'll get an undefined index error on each iteration of the second foreach
loop because you're trying to do +=
on a value that isn't defined.
Also, if you're trying add the values of Billed
and Route
then storing them in different parts of an associative array ($sum2[$stat_name]
) is an extra step. Just add them together in the same key of the array.