<?php
error_reporting(E_ALL);
$test_array = Array(Array
(
"pid" => 1,
"encounter" => 20,
"code" => abc,
"fee" => 300.00
),
Array
(
"pid" => 1,
"encounter" => 20,
"code" => abc,
"fee" => 300.00
),
Array
(
"pid" => 2,
"encounter" => 20,
"code" => abc,
"fee" => 80
),
Array
(
"pid" => 3,
"encounter" => 20,
"code" => xyz,
"fee" => 90
),
Array
(
"pid" => 5,
"encounter" => 40,
"code" => xyz,
"fee" => 100
),
Array
(
"pid" => 3,
"encounter" => 40,
"code" => xyz,
"fee" => 100
),
Array
(
"pid" => 2,
"encounter" => 20,
"code" => abc,
"fee" => 80
),
Array
(
"pid" => 1,
"encounter" => 20,
"code" => xyz,
"fee" => 40
));
//Declaration...
$pre_pid = "";
$pre_encounter = "";
$pre_code = "";
$pre_fee = "";
$sum_charges = 0;
/*Foreach loop*/
$i=0;
foreach($test_array as $my_arr){
$pre_pid = $my_arr['pid'];
$pre_encounter = $my_arr['encounter'];
$pre_code = $my_arr['code'];
if($pre_pid == $my_arr['pid'] && $pre_encounter == $my_arr['encounter'] && $pre_code == $my_arr['code']){
echo "FEE-AMOUNT=".$my_arr['fee'];
$sum_charges+=$my_arr['fee'];
echo '<br/>';
}
$i++;
}
//Getting Sum = 1090
//Actual Sum I needed = 710
?>
你好朋友我想上面的代碼,我想要費用應該計算誰擁有相同的3鍵值對。 例如,如果每個數組3鍵值相同,則只計算這些費用數量。PHP陣列總和通過相同的鍵值對需要計算
這裏實施代碼,不使用引擎收錄或別的東西,這些鏈接arn't永久.. – Naruto
粘貼您的代碼在這裏 –
或陣列例如你試試這個[答案]之前和之後 –