I'm working on some loan project with php which installments are created by the code below. Note:the first installment should be dated to the next month from $loanyearacc and $loanmonthacc. for example if the loan accepted in 12/01/2018,the first installment is 01/01/2019 the code is:
$loanmonthacc=12;
$loanyearacc=2018;
$loanreqmonth=18;
for($i=$loanmonthacc+1;$i<=$loanmonthacc+$loanreqmonth+1;$i++){
if($i%12==0){
$m=12;
}
else{
$m=$i%12;
}
echo 'i: '.$i.'year: '.$loanyearacc.'month: '.$m.'<br>';
if($i%12==0){
$loanyearacc++;
}
if($i%13==0){
$loanyearacc++;
}
}
Code above works fine just in case that $loanmonthacc is not equal to 12. but if $loanmonthacc equals to 12, JUST the first installment would be next month BUT the year wont increase. can anyone please help me? Sorry for my weak english guys :)
You simply run the counter YEAR | MONTH for the number of required months - exactly as the mileage in your car, i.e. the next month after 12 is again 1 but then you also increase the year:
$loanmonthacc=12;
$loanyearacc=2018;
$loanreqmonth=18;
$installment = 1;
while($loanreqmonth)
{
$loanmonthacc++;
if($loanmonthacc > 12)
{
$loanmonthacc = 1;
$loanyearacc++;
}
echo "Installment $installment = $loanmonthacc / $loanyearacc <br>";
$loanreqmonth--;
}