<?php
function calcPayment($creditSum,
$percent,
$servicePayment,
$monthlyPayment,
$openPayment){
$paymentTotal = 0;
for($month = 1; $creditSum > 0; $month++){
$creditSum = $creditSum * $percent + $servicePayment;
if ($creditSum <= $monthlyPayment) {
$paymentTotal += $creditSum;
$creditSum = 0;
} else {
$creditSum -= $monthlyPayment;
$paymentTotal = $paymentTotal + $monthlyPayment;
}
}
$paymentTotal = $paymentTotal + $openPayment;
return $paymentTotal;
}
$creditSum = 39999;
$payout = 5000;
$homoCreditTotal = round(calcPayment
($creditSum, 1.04, 500, $payout, 0),2); $softbankTotal = round(calcPayment
($creditSum, 1.03, 1000, $payout, 0),2); $strawberryBankTotal = round(calcPayment
($creditSum, 1.02, 0, $payout, 7777),2);
echo "homoCredit: {$homoCreditTotal} руб.\n";
echo "softbank: {$softbankTotal} руб.\n";
echo "strawberryBank: {$strawberryBankTotal} руб.\n";
$bankOffer = ['homoCredit' => $homoCreditTotal, 'softbank' => $softbankTotal, 'strawberryBank' => $strawberryBankTotal];
echo "\nНаиболее выгодное предложение от {$bank[0]}\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjYWxjUGF5bWVudCgkY3JlZGl0U3VtLCAKCQkJCQkgJHBlcmNlbnQsIAoJCQkJCSAkc2VydmljZVBheW1lbnQsIAoJCQkJCSAkbW9udGhseVBheW1lbnQsIAoJCQkJCSAkb3BlblBheW1lbnQpewoJJHBheW1lbnRUb3RhbCA9IDA7Cglmb3IoJG1vbnRoID0gMTsgJGNyZWRpdFN1bSA+IDA7ICRtb250aCsrKXsKCQkkY3JlZGl0U3VtID0gJGNyZWRpdFN1bSAqICRwZXJjZW50ICsgJHNlcnZpY2VQYXltZW50OwoJCWlmICgkY3JlZGl0U3VtIDw9ICRtb250aGx5UGF5bWVudCkgewoJCQkkcGF5bWVudFRvdGFsICs9ICRjcmVkaXRTdW07CgkJCSRjcmVkaXRTdW0gPSAwOwoJCX0gZWxzZSB7CgkJCSRjcmV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