2013-09-28 62 views
-1

如果我輸入P200,000的金額,然後我每月支付如下:如何根據收到的金額瞭解剩餘的每月付款?

############################### 
# Monthly Payments ## Remarks # 
############################### 
# 43,590   ## Pending # 
# 43,590   ## Pending # 
# 43,590   ## Pending # 
# 43,590   ## Pending # 
# 43,590   ## Pending # 
############################### 

我每月付款的陣列。那麼,我將如何知道P200,000每月支付的付款額是多少,並將評論更改爲「ENCASHED」?

我想要的結果是這樣的:

############################### 
# Monthly Payments ## Remarks # 
############################### 
# 43,590   ## Encashed# 
# 43,590   ## Encashed# 
# 43,590   ## Encashed# 
# 43,590   ## Encashed# 
# 43,590   ## Pending # 
############################### 

如何在PHP代碼呢?

+0

你如何分割20萬分期付款,並告訴我們你在數組 – Shafeeque

回答

0

只是遍歷支付,減去總額在每次支付的金額,直到有足夠的錢:

// Just testing initialization 
$payments = array_fill(0, 5, array('sum' => 43590, 'status' => 'Pending')); 
$totalSum = 200000; 

foreach ($payments AS &$payment) { 
    if ($totalSum >= $payment['sum']) { 
    $totalSum -= $payment['sum']; 
    $payment['status'] = 'Encashed'; 
    } else { 
    break; 
    } 
} 

參見:http://phpfiddle.org/lite/code/nqe-yfd

相關問題