我的代码运行完美。我的问题是如何总结$ manpowerCost和$ otherCharges的所有价值?
for ($i = 1; $i<=9; $i++) {
$m = '0'.$i;
$sumMc = array();
$revenue = revenue($project, $year.'-'.$m);
$manpowerCost = manpowerCost($project, $year.'-'.$m);
$otherCharges = otherCharges($project, $year.'-'.$m);
$netIncome = netIncome($revenue, $manpowerCost, $otherCharges);
if ($manpowerCost<=0 && $m <= $projected_date){
$manpowerCost = round(($projected_mc * $percentage_mc),2);
$projected_total_mc += $manpowerCost;
$pt = $pt + $manpowerCost;
} else {
$projected_mc = $manpowerCost;
$manpowerCost = $projected_mc;
}
if ($otherCharges<=0 && $m <= $projected_date){
$otherCharges = round(($projected_oc * $percentage_oc),2);
$projected_total_oc += $otherCharges;
$pt = $pt + $otherCharges;
} else {
$projected_oc = $otherCharges;
$otherCharges = $projected_oc;
}
echo '<td>RE:'.number_format($revenue, 2, '.', '').'<br />MC:'.number_format($manpowerCost, 2, '.', '').'<br />OC:'.number_format($otherCharges, 2, '.', '').'<br />NI:'.$netIncome.'</td>';
}
答案 0 :(得分:0)
你可以尝试这样
$powercost_total = '0';
for ($i = 1; $i<=9; $i++) {
$manpowerCost = manpowerCost($project, $year.'-'.$m);
$powercost_total = $manpowerCost + 4powercost_total;
....
答案 1 :(得分:0)
在循环外声明$ TotalManPowerCost和$ TotalOtherCharges变量,并在循环的每次迭代中为它们添加$ manpowercost和$ otherCharges