<?php
 
error_reporting(-1);
mb_internal_encoding('utf-8');


function calculateCredit($rate, $servicePayment, $startPayment) {
	
	$creditBalance = 39999 + $startPayment;
	$monthlyPayment = 5000;
	$totalPayment = 0;
	
	for ($month = 1; $month <= 20; $month++) {
		$creditBalance = ($creditBalance * $rate) + $servicePayment;
		if ($creditBalance <= $monthlyPayment) {
			$totalPayment = $totalPayment + $creditBalance;
			$creditBalance = 0;
			echo "Credit balance ={$creditBalance}, Month: {$month}, total payments: {$totalPayment} \n";
			break;
		}
		$creditBalance = $creditBalance - $monthlyPayment;
		$totalPayment = $totalPayment + $monthlyPayment;
		echo "Credit balance ={$creditBalance}, Month: {$month}, total payments: {$totalPayment} \n";

	}
}

$homoCredit = calculateCredit(1.04, 500, 0);
echo "HomoCredit total: {$homoCredit} \n";
$softBank = calculateCredit(1.03, 1000, 0);
echo "SoftBank total: {$softBank} \n";
$strawberryBank = calculateCredit(1.02, 0, 7777);
echo "StrawberryBank total: {$strawberryBank} \n";