2013-09-28 46 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

相关问题