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条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题