【发布时间】:2014-03-03 20:50:41
【问题描述】:
在 CI 中工作,想要遍历一个 result_array 并从一个数量键值中添加值。数组是多维的
array(2)
{
[0]=> array(9)
{
["id"]=> string(1) "1"
["resident_id"]=> string(1) "1"
["charge_amt"]=> string(6) "250.00"
["charge_key"]=> string(3) "HOM"
["charge_desc"]=> string(25) "Homeowner Association Fee"
["charge_date"]=> string(19) "2014-03-04 03:08:08"
["active"]=> string(1) "1"
["created_at"]=> string(19) "2014-03-03 14:17:00"
["updated_at"]=> NULL
}
[1]=> array(9)
{
["id"]=> string(1) "2"
["resident_id"]=> string(1) "1"
["charge_amt"]=> string(5) "25.00"
["charge_key"]=> string(3) "LAT"
["charge_desc"]=> string(8) "Late Fee"
["charge_date"]=> string(19) "2014-03-04 04:11:10"
["active"]=> string(1) "1"
["created_at"]=> string(19) "2014-03-03 04:10:09"
["updated_at"]=> NULL
}
}
如何让它遍历每个数组并将每个 ["charge_amt"] 相加,然后打印一次最终计算?
【问题讨论】:
标签: php arrays codeigniter multidimensional-array