-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 に答える