总结一个foreach结果PHP

奥克塔维奥·圣罗曼

我在将结果汇总到php时遇到麻烦,我有以下代码:

[<?php foreach($results2 as $i) : ?>
                <?php echo $i['count'] ?>,
            <?php endforeach; ?>]

那回声:

0,0,0,0,7,0,2

我想对这些值求和,而不是回显每个值,我尝试使用,count($i)但是它不起作用

生活

array_sum结合使用array_column

$count = array_sum(array_column($results2, 'count'));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章