-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 上编写代码?

4

1 回答 1

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

于 2013-09-28T08:34:26.700 回答