I have 3 level nested array and I would like some help to make the generate the sum of its values. The array goes like
SUM
/ \
A B
/ \ /\
Billed Route Billed Route
/ \ / \
Value Value Value Value
How can i make a sum of the Billed and Route fields?
So far I have this code
foreach($sum as $client)
{
$s = 0;
foreach($client as $stat_name=>$stat_value)
{
$val = 0;
// echo "<br><u><i>";
// echo $stat_name;
// echo "</u></i><br>";
foreach($stat_value as $value)
{
$val += intval($value);
}
$sum2[$stat_name] += $val;
}
}
I receive an undefine index error on the first loop for each new key.
if (isset($sum2[$stat_name])) { /* do += */ } else { /* do = */ }print_rof array would help, as there is a much easier way.