下面是顯示月份用戶數據的數組輸出。我需要爲不同的資源獲得ACTUAL_HOURS
的總和。PHP - 基於密鑰的數組值的總和
對於以下情況,月的User 1 and User 2
的ACTUAL_HOURS之和應爲10 + 20 = 30
。 也是一樣AUG-2015
是80 + 20 = 100
$user_array
輸出
Array
(
[User 1] => Array
(
[JUL-2015] => Array
(
[SITE_STATUS] => Offshore
[ACTUAL_HOURS] => 10
[PROJECTED_HOURS] => 20
)
[AUG-2015] => Array
(
[SITE_STATUS] => Offshore
[ACTUAL_HOURS] => 80
[PROJECTED_HOURS] => 88
)
)
[User 2] => Array
(
[JUL-2015] => Array
(
[SITE_STATUS] => Offshore
[ACTUAL_HOURS] => 20
[PROJECTED_HOURS] => 0
)
[AUG-2015] => Array
(
[SITE_STATUS] => Offshore
[ACTUAL_HOURS] => 20
[PROJECTED_HOURS] => 0
)
)
)
$project_months
輸出
Array
(
[0] => JUL-2015
[1] => AUG-2015
)
循環中的數據如下面給出求和而不是User 1
foreach ($user_array as $user_name => $user_data) {
foreach ($project_months as $month) {
}
}
如何顯示ACTUAL_HOURS
或PROJECTED_HOURS
對不同資源月份的總和?如上所示?
你爲什麼不用db計算所有這些? (如果你保留db的數據當然。) – Alex