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++;
}
?>
Storing Iteration Data In an Array
Moderator: General Moderators
Re: Storing Iteration Data In an Array
Am not quite sure what you mean, as storing the data to an array is very easy, but am sure I am missing something from your explanation. Can you go into more detail about what you need to do please?
Re: Storing Iteration Data In an Array
I need the payment values (1182.47) in an array repeated as many times as the term. In other words, if the term was 360 then the payment would be stored in an array 360 times. The array would be used in another section of the code outside of the iteration. Does that make sense?