0

So I'm creating this php local site for my work it is about mortgage and I made this code as a begging

<?php 
$income=1650;
$rate=7;
$period=240;
$graduation =60;
$paytoinc=40;
$rowage=7;
for ($l=1; $l <= $period ; $l++) { 
    for ($i=1; $i <= $graduation ; $i=+12) { 
        $NPV = (1/pow(1+($rate/100)/12, $i));
        $income = $income*(1+($rowage/100));
        $mpayment = $income *$paytoinc/100 ;
    }
    echo $mpayment = $income *$paytoinc/100 ;
}
?> 

I have 2 periods , 1 is included in the other for some reason this is making endless loop , I'm new so can anyone tell me what am I missing and doing wrong ?

1
  • So as well as the correct answer below by @bart-friederichs there is a reasonable amount of redundancy in the code. You are evaluating $mpayment on each iteration of the inner loop but only using the final value that you calculate in the last line of your outer loop. You could remove this line from the inner loop to increase efficiency. Commented Jul 13, 2017 at 10:40

1 Answer 1

4

You are make a mistake here:

for ($i=1; $i <= $graduation ; $i=+12) { 

$i=+12 will assign 12 to $i. Change to:

for ($i=1; $i <= $graduation ; $i+=12) { 

That being said, learn how to debug. This bug would come up quite quickly if you echo'd $i in the innermost loop.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks lots :3 sorry for making you answer for something really stupid xD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.