我在将结果汇总到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] 删除。
我来说两句