There is a method (array_sum) in PHP that adds the values of a two-dimensional array without having to traverse the array, but in this case I need to traverse that array without using this method to display the values per array and its total .
Axis:
$total = 0;
$numbers = ["SUMA1" => [8,5,1,5], "SUMA2" => [2,2,5]];
foreach ($numbers as $value) {
foreach ($value as $valores) {
$total += $valores;
}
}
echo "el total es: ".$total;
When doing the echo
shows me the total of both ('SUMA1', 'SUMA2')
fixes, what I could not achieve is that I printed the sum per arrangement, that is:
El total de 'SUMA1' es 19
El total de 'SUMA2' es 9