【发布时间】:2012-10-02 01:38:46
【问题描述】:
我已经看到关于这个问题的各种帖子,所以我知道可能存在一些答案。然而,在阅读了这些之后,我并没有变得更聪明。
我有一个如下所示的数组。
[0] => Array
(
[id] => 95659865986
[invoiceNumber] => 6374324
[invoiceTitle] => Monthly
[invoiceStatus] => Paid
[accountId] => 6235218753
[totalExVat] => 158.95
[dateCreated] => 1 Apr 2012
[vatAmount] => 20.00
)
我想做的就是对这个数组的vatAmount 值进行数组求和。
因为以下似乎没有做太多。
(array_sum($account_invoices['vatAmount'])
【问题讨论】:
-
数组中只有一个“vatAmount”元素,不宜相加。
-
假设 $account_invoices 是你的多维数组,$account_invoices['vatAmount'] 没有定义,而 $account_invoices[0]['vatAmount'] 是。