Storing Iteration Data In an Array
Posted: Mon Nov 17, 2008 9:35 am
The following code calculates a mortgage payment and the interest paid. I need to capture the individual payments in an array. ($a = number_format($monthly_payment, 2);) I can't figure out how to load the array.
It would look something like $array(1182.47, 1182.47, 1182.47, 1182.47,....)
Can anyone help?
<?php
$rate = .06875;
$monthly_interest_rate = $rate/12;
$month_term = 360;
$financing_price = 180000;
$year_term = 30;
$principal = $financing_price;
$current_month = 1;
$current_year = 1;
$power = -($month_term);
$denom = pow((1 + $monthly_interest_rate), $power);
$monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom));
while ($current_month <= $month_term) {
$interest_paid = $principal * $monthly_interest_rate;
$principal_paid = $monthly_payment - $interest_paid;
$remaining_balance = $principal - $principal_paid;
$a = number_format($monthly_payment, 2);
$principal = $remaining_balance;
$current_month++;
}
?>
It would look something like $array(1182.47, 1182.47, 1182.47, 1182.47,....)
Can anyone help?
<?php
$rate = .06875;
$monthly_interest_rate = $rate/12;
$month_term = 360;
$financing_price = 180000;
$year_term = 30;
$principal = $financing_price;
$current_month = 1;
$current_year = 1;
$power = -($month_term);
$denom = pow((1 + $monthly_interest_rate), $power);
$monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom));
while ($current_month <= $month_term) {
$interest_paid = $principal * $monthly_interest_rate;
$principal_paid = $monthly_payment - $interest_paid;
$remaining_balance = $principal - $principal_paid;
$a = number_format($monthly_payment, 2);
$principal = $remaining_balance;
$current_month++;
}
?>