doupingyun73833 2013-07-26 09:25
浏览 62
已采纳

在php中将for循环的变量返回值加起来

I have this code that is working perfectly. My question is how can I sum all the value of $manpowerCost and $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>';
}
  • 写回答

2条回答 默认 最新

  • doublestar2014 2013-07-26 09:29
    关注

    U can Try like this

    $powercost_total = '0';
    for ($i = 1; $i<=9; $i++) {
    $manpowerCost = manpowerCost($project, $year.'-'.$m);
    $powercost_total = $manpowerCost + 4powercost_total;
    ....
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集