<?php

error_reporting(-1);

function total ($priseIpad, $payStart, $percent, $mounthPay, $comission) 
{
	$creditSum = ($priseIpad + $payStart);
	$paid = 0;
	
	for($creditSum = ($creditSum * $percent); $creditSum > 0;)
	{
		$creditSum = $creditSum + $comission;
		if($creditSum > $mounthPay)
		{
			$paid = $paid + $mounthPay;
			$creditSum = $creditSum - $mounthPay;
		}
		
		else($creditSum < $mounthPay);
		{
			$paid = $paid + $creditSum;
			$creditSum = $creditSum - $creditSum;
		}
		return $paid;
	}
	
}

$creditSum = 39999;
$mounthPay = 5000;

$homoPer = 1.04;
$homoCom = 500;

$homoCredit = total ($creditSum,1,$homoPer,$mounthPay, $homoCom);

$softPer = 1.03;
$softCom = 1000;

$softBank = total ($creditSum,1,$softPer,$mounthPay, $softCom);

$strwPer = 1.02;
$payStartStwr = 7777;

$strwBank = total ($creditSum,$payStartStwr,$strwPer,$mounthPay,0);

echo "homoCredit обошелся в {$homoCredit} руб \n";
echo "softBank обошелся в {$softBank} руб \n";
echo "strwBank обошелся в {$strwBank} руб \n";
 
 ?>