在foreach循环php中求和值

2021-12-26 00:00:00 count foreach php
foreach($group as $key=>$value)
{
    echo $key. " = " .$value. "<br>";
}

例如:

文档 1 = 8

文档 2 = 7

doc3 = 1

我想计算$value,所以结果是8+7+1 = 16.我该怎么办?

I want to count $value, so the result is 8+7+1 = 16. What should i do?

谢谢.

推荐答案

$sum = 0;
foreach($group as $key=>$value)
{
   $sum+= $value;
}
echo $sum;

相关文章