0
我有如下所示的數組。我想要得到一個結果數組,其中[tv]
,[tu]
,[cost]
,[km]
的值對所有具有相同值[tick_id]
的行進行求和。在這個例子中,我們應該總結數組元素0,1,2,...的值[tv]
,[tu]
,[cost]
,[km]
...我該怎麼做?與嵌套關聯數組中相同鍵關聯的值的總和
Array (
[0] => stdClass Object (
[id] => 15
[user_id] => 44
[name] => inspector1
[tv] => 0.00
[tc] => 0.00
[tu] => 0.00
[cost] => 0.00
[kms] => 0
[date_s] => 2012-03-30
[notes] =>
[tick_id] => 11
[tot_fee] => 5500
)
[1] => stdClass Object (
[id] => 39
[user_id] => 46
[name] => Assistant
[tv] => 10.00
[tc] => 0.00
[tu] => 4.50
[cost] => 0.00
[kms] => 120
[date_s] => 2012-03-31
[notes] =>
[tick_id] => 15
[tot_fee] => 0
)
[2] => stdClass Object (
[id] => 35
[user_id] => 46
[name] =>
[tv] => 0.00
[tc] => 0.00
[tu] => 0.00
[cost] => 0.00
[kms] => 0
[date_s] => 2012-03-30
[notes] =>
[tick_id] => 13
[tot_fee] => 3200
)
…
)
這是可能的。你有沒有嘗試使用'foreach'來迭代和求和? – Jon 2012-04-04 07:42:38
使用var_export導出數據結構而不是print_r。 TYIA – jpic 2012-04-04 07:45:04