我使用的API返回JSON对象,然后使用
我需要获得数组中所有[data]
项的计数,然后生成每个项中包含的所有[Total]
值的总和
下面是我的数组:
Array
(
[errorCode] => 0
[result] => OK
[data] => Array
(
[0] => Array
(
[fieldData] => Array
(
[Due Date] => 11/30/2017
[Date] => 11/30/2017
[Total] => 128.97
[Customers::Company] => A B C Lock & Key
[Status] => Paid
[Date Payment] => 11/30/2017
)
[portalData] => Array
(
)
[recordId] => 1
[modId] => 4
)
[1] => Array
(
[fieldData] => Array
(
[Due Date] => 12/01/2017
[Date] => 12/01/2017
[Total] => 256
[Customers::Company] => Kim Peacock Beringhause
[Status] => Paid
[Date Payment] => 12/01/2017
)
[portalData] => Array
(
)
[recordId] => 2
[modId] => 3
)
[2] => Array
(
[fieldData] => Array
(
[Due Date] => 11/30/2017
[Date] => 11/30/2017
[Total] => 1880
[Customers::Company] => Norton, Robert L Esq
[Status] => Unpaid Overdue
[Date Payment] =>
)
[portalData] => Array
(
)
[recordId] => 3
[modId] => 0
)
[3] => Array
(
[fieldData] => Array
(
[Due Date] => 12/22/2017
[Date] => 12/22/2017
[Total] => 1278
[Customers::Company] => Shapiro, Mark R Esq
[Status] => Unpaid
[Date Payment] =>
)
[portalData] => Array
(
)
[recordId] => 10
[modId] => 1
)
)
)
我试过了
count($array)
它返回3
,我可以看到这是该父数组中3项(errorCode、result和data)的计数,但我无法确定如何仅关注data
。
我需要的计数值是4
,总值是3542.97
。
1条答案
按热度按时间p5cysglq1#
对于计数,您需要:
为了得到所有
Total
索引值的和:***参考:-***PHP: array_column - Manual