Passionate full stack web developer, course author for Educative, book author for Packt, he/him.
Find my work and get to know me on my Linktree: https://linktr.ee/thormeier
A nested array can be summed up using array_sum for example. You could, for example, do something like this:
$sum=array_sum($m[0]);// Sums up $m[0][0] + $m[0][1] + $m[0][2] etc.$percentageM00=$m[0][0]/$sum;$percentageM01=$m[0][1]/$sum;$percentageM02=$m[0][2]/$sum;
If, on the other hand, you want to sum up the rows (so, $m[0][0], $m[1][0]$m[2][0] etc.), you need to get those values first. You could use a foreach for that:
A nested array can be summed up using
array_sum
for example. You could, for example, do something like this:If, on the other hand, you want to sum up the rows (so,
$m[0][0]
,$m[1][0]
$m[2][0]
etc.), you need to get those values first. You could use a foreach for that:Does that help you?
Thank You ❤