Desperate For Array Help
Posted: Thu Dec 10, 2009 7:08 pm
I have a problem that I hope isn't too unusual. There's a good chance that I'm just approaching the whole thing from the wrong angle. So I'll describe the whole thing.
My array is this:
1. I have a function called nper() that calculates the number of payments left on a debt. It mirrors the function of the same name in MS Excel. I actually have to calculate nper twice (before and after comparison). I store the results of the first nper calculation (along with some other data) in an array and sort nper ascending.
2. I have a variable called $margin which is an additional amount applied ONLY to the debt with the lowest nper() result. The other debts in the array will have their balances reduced by ($nper * $minpay).
3. Before calculating nper() on the second debt, $margin = $margin + $minpay(debt1). Then $nper = $nper + $nper(debt1). The reason for this is that I need a running total of how many months it takes to pay off each debt.
The end result I really need is $nper for the last debt.
Since there are x number of debts, I obviously have to loop through this. Here's my problem:
I cannot figure out a way to loop through the array and get the results I want.
debt1 = $nper(apr, pmt, pv, margin) but the remaining debts get $balance = $balance - $minpay.
As I said, I'm probably just going about this the wrong way and my programming skills are still on the basic side.
Thanks!
My array is this:
1. I have a function called nper() that calculates the number of payments left on a debt. It mirrors the function of the same name in MS Excel. I actually have to calculate nper twice (before and after comparison). I store the results of the first nper calculation (along with some other data) in an array and sort nper ascending.
2. I have a variable called $margin which is an additional amount applied ONLY to the debt with the lowest nper() result. The other debts in the array will have their balances reduced by ($nper * $minpay).
3. Before calculating nper() on the second debt, $margin = $margin + $minpay(debt1). Then $nper = $nper + $nper(debt1). The reason for this is that I need a running total of how many months it takes to pay off each debt.
The end result I really need is $nper for the last debt.
Since there are x number of debts, I obviously have to loop through this. Here's my problem:
I cannot figure out a way to loop through the array and get the results I want.
debt1 = $nper(apr, pmt, pv, margin) but the remaining debts get $balance = $balance - $minpay.
As I said, I'm probably just going about this the wrong way and my programming skills are still on the basic side.
Thanks!