多维数组array_sum [英] multidimensional array array_sum
本文介绍了多维数组array_sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看到关于这个问题的各种帖子,所以我知道可能存在一些答案.然而,在阅读这些之后,我并不聪明.
I have seen various posted about this question so am aware some answers to this may exist. however I am none the wiser after reading these.
我有一个如下所示的数组.
I have an array that is like the following.
[0] => Array
(
[id] => 95659865986
[invoiceNumber] => 6374324
[invoiceTitle] => Monthly
[invoiceStatus] => Paid
[accountId] => 6235218753
[totalExVat] => 158.95
[dateCreated] => 1 Apr 2012
[vatAmount] => 20.00
)
我想要做的就是对这个数组的 vatAmount
值进行数组求和.
All I wish to do is do array sum on the vatAmount
values of this array.
因为以下内容似乎没有多大作用.
As the following doesnt seem to be doing much.
(array_sum($account_invoices['vatAmount'])
推荐答案
只是一种方法:
$sum = 0;
foreach($account_invoices as $num => $values) {
$sum += $values[ 'vatAmount' ];
}
这篇关于多维数组array_sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文