2013-07-26 2 views
0

이 코드는 완벽하게 작동합니다. 제 질문은 어떻게하면 $ manpowerCost와 $ otherCharges의 모든 가치를 합산 할 수 있습니까?변수의 값을 합산하여 for 루프의 for 루프

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

U이

$powercost_total = '0'; 
for ($i = 1; $i<=9; $i++) { 
$manpowerCost = manpowerCost($project, $year.'-'.$m); 
$powercost_total = $manpowerCost + 4powercost_total; 
.... 
+0

감사를 반복 할 때마다 그들에게 otherCharges를 $의 manpowercost를 추가하고 $ ,이 작동합니다. 많이 감사합니다. – jules

0

선언 $의 TotalManPowerCost 같은 시도 할 수 있으며 $ TotalOtherCharges의 루프의 외부 변수, 루프