<?php

error_reporting(-1);
 
$credit = 1000;
$percent = 0.03;
$commission = 1000;
$payment = 5000;
 
$rate = 1 + $percent;
 
do {
    $credit = $credit * $rate + $commission;
    $log .= "Current month sum: $credit \n";
 
    $credit -= $payment;
    $log .= "Sum, after anon paid: $credit \n";
 
    $period++;
    $log .= "Current month $period\n\n";
 
} while (($credit * $rate + $commission) > $payment);

$credit = $credit * $rate + $commission;
 
$log .= "Current month sum: $credit \n";
 
$sum = $period * $payment + $credit;
$credit = 0;
$period++;
 
$log .= "Sum, after anon paid: $credit\n"."Current month $period\n\n";
 
echo "Anon paid for $period month. \n Whole sum: $sum.\n Credit: $credit \n\n";
echo $log;