<?php

error_reporting(-1);

function credit($summa, $persent, $plusVMesyac, $nachalniyVznos, $plataVMes)
{
    
    $vsyaSumma      = $summa + $nachalniyVznos;
    $skolkoViplatil = 0;
    for ($i = 1; $i <= 100; $i++) {
        $vsyaSumma = ($vsyaSumma * $persent + $plusVMesyac);
        
        if ($vsyaSumma > $plataVMes) {
            $vsyaSumma = $vsyaSumma - $plataVMes;
        } else {
            $plataVMes = $vsyaSumma;
            $vsyaSumma = $vsyaSumma - $plataVMes;
        }
        $skolkoViplatil = $skolkoViplatil + $plataVMes;
        
        
        if ($vsyaSumma <= 0) {
            return $skolkoViplatil;
            break;
        }
    }
}


$creditsum           = 39999;
$payount             = 5000;
$homoCreditTotal     = credit($creditsum, 1.04, 500, 0, $payount);
$softBankTotal       = credit($creditsum, 1.03, 1000, 0, $payount);
$strawberryBankTotal = credit($creditsum, 1.02, 0, 7777, $payount);

echo "homoCredit: {$homoCreditTotal} рублей \n";
echo "softBankTotal: {$softBankTotal} рублей\n";
echo "strawberryBankTotal: {$strawberryBankTotal} рублей \n";