fork download
  1. <?php
  2.  
  3.  
  4. function calcPayment($creditSum,
  5. $percent,
  6. $servicePayment,
  7. $monthlyPayment,
  8. $openPayment){
  9. $paymentTotal = 0;
  10. for($month = 1; $creditSum > 0; $month++){
  11. $creditSum = $creditSum * $percent + $servicePayment;
  12. if ($creditSum <= $monthlyPayment) {
  13. $paymentTotal += $creditSum;
  14. $creditSum = 0;
  15. } else {
  16. $creditSum -= $monthlyPayment;
  17. $paymentTotal = $paymentTotal + $monthlyPayment;
  18. }
  19. }
  20. $paymentTotal = $paymentTotal + $openPayment;
  21. return $paymentTotal;
  22. }
  23. $creditSum = 39999;
  24. $payout = 5000;
  25. $homoCreditTotal = round(calcPayment($creditSum, 1.04, 500, $payout, 0),2);
  26. $softbankTotal = round(calcPayment($creditSum, 1.03, 1000, $payout, 0),2);
  27. $strawberryBankTotal = round(calcPayment($creditSum, 1.02, 0, $payout, 7777),2);
  28.  
  29. echo "homoCredit: {$homoCreditTotal} руб.\n";
  30. echo "softbank: {$softbankTotal} руб.\n";
  31. echo "strawberryBank: {$strawberryBankTotal} руб.\n";
  32.  
  33. $bankOffer = ['homoCredit' => $homoCreditTotal, 'softbank' => $softbankTotal, 'strawberryBank' => $strawberryBankTotal];
  34. asort($bankOffer);
  35. $bank = array_keys($bankOffer);
  36. echo "\nНаиболее выгодное предложение от {$bank[0]}\n";
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
homoCredit: 56423.56 руб.
softbank: 61268.72 руб.
strawberryBank: 51806.37 руб.

Наиболее выгодное предложение от strawberryBank