多维数组array_sum [英] multidimensional array array_sum
本文介绍了多维数组array_sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我所看到的各种发布了关于这个问题,所以我知道一些答案,这可能存在。然而,我没有看完这些明智。
我有一个数组,它是像下面这样。
[0] =>排列
(
[ID] => 95659865986
[invoiceNumber] => 6374324
[invoiceTitle] =>每月一次
[invoiceStatus] =>付费
[帐户ID] => 6235218753
[totalExVat] => 158.95
[dateCreated会] => 2012年4月1日
[vatAmount] => 20.00
)
我所希望做的是做这个数组的 vatAmount
值数组总和。
由于以下似乎并不被太多做的。
(array_sum($ account_invoices ['vatAmount'])
解决方案
只是一个办法做到这一点:
$总和= 0;的foreach($ account_invoices为$ NUM => $值){
$总和+ = $值['vatAmount'];
}
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
)
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'])
解决方案
Just a way to do it:
$sum = 0;
foreach($account_invoices as $num => $values) {
$sum += $values[ 'vatAmount' ];
}
这篇关于多维数组array_sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文