PHP Array Calculation -
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 )
code
$test_cnt = 0; test_encounter_pid = array(); foreach($provinnrarr $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']; } }
hello friends, above array trying sum array fee key related values when pid , encounter different getting 1,876.30 total actual need 1,576.30 because 300 adding of 2nd array value. not getting how resolve it.
try this,
foreach($array $val){ if($val['pid'] != "0"){ if (!in_array($val['pid'], $temp_array)) { $temp_array[] = $val['pid']; $total += $val['fee']; } } echo $total;
Comments
Post a Comment