如何根据收到的金额知道剩余的每月付款

  • 本文关键字:付款 金额知 何根 php
  • 更新时间 :
  • 英文 :


如果我输入P200,000的金额,那么我的每月付款如下:

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

我的每月付款是一致的。然后,我如何知道P200,000是否将涵盖多少每月付款并将备注更改为"兑现"?

我想要这样的结果:

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

如何在 PHP 上对此进行编码?

只需迭代付款并从总金额中减去每笔付款的总和,直到有足够的钱:

// 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

最新更新