Storing Iteration Data In an Array

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mortman
Forum Newbie
Posts: 2
Joined: Mon Nov 17, 2008 9:21 am

Storing Iteration Data In an Array

Post by mortman »

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++;
}

?>
User avatar
idevlin
Forum Commoner
Posts: 78
Joined: Tue Jun 26, 2007 1:10 pm
Location: Cambridge, UK

Re: Storing Iteration Data In an Array

Post by idevlin »

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?
mortman
Forum Newbie
Posts: 2
Joined: Mon Nov 17, 2008 9:21 am

Re: Storing Iteration Data In an Array

Post by mortman »

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?
Post Reply