Array
(
[pid] => 877
[encounter] => 15342
[fee] => 300.00
)
Array
(
[pid] => 877
[encounter] => 15342
[fee] => 300.00
)
Array
(
[pid] => 1422
[encounter] => 15332
[fee] => 600.00
)
Array
(
[pid] => 690
[encounter] => 15335
[fee] => 0.00
)
Array
(
[pid] => 690
[encounter] => 15335
[fee] => 276.30
)
Array
(
[pid] => 690
[encounter] => 15335
[fee] => 0.00
)
Array
(
[pid] => 690
[encounter] => 15335
[fee] => 0.00
)
Array
(
[pid] => 690
[encounter] => 15338
[fee] => 400.00
)
代碼PHP陣列計算
$test_cnt = 0;
test_encounter_pid = array();
foreach($provInnrArr as $dataDispArr){
$test_encounter_pid['pid'] = $dataDispArr['pid'];
$test_encounter_pid['encounter'] = $dataDispArr['encounter'];
$test_encounter_pid['fee'] = $dataDispArr['fee'];
if (in_array($dataDispArr["encounter"], $test_encounter_pid)) {
$test_cnt += $dataDispArr['fee'];
}
}
朋友你好,以上是我的陣列我想求和所有陣列費鍵相關的值,只有當PID和遇到的是不同的 我越來越1,876.30合計但實際我需要是1,576.30 由於第二個數組值增加了300。我沒有得到如何解決它。
做一個foreach循環,並檢查PID是相同與否,如果是再加入則費用到一個新的變量,最後呼應的變量。 –
'array_sum(array_column(array_unique($ array,SORT_REGULAR),「fee」)))'? – apokryfos
告訴我們你正在做什麼計算 – RiggsFolly