# PHP: Excel PMT

The Microsoft Excel PMT function calculates the payment for a loan based on constant payments and a constant interest rate. Syntax: PMT(rate, nper, pv, fv, type).

• Rate is the interest rate for the loan
• Nper is the total number of payments for the loan
• Pv is the present value, or the total amount that a series of future payments is worth now
• Fv is the future value, or a cash balance you want to attain after the last payment is made. If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0
• Type is the number 0 (zero) or 1 and indicates when payments are due
• 0 or omitted At the end of the period
• 1 At the beginning of the period
```/** * This is the PHP version of the PMT function used in Excel * * @param float \$rate * @param int \$nper * @param float \$pv * @param float \$fv * @param int \$type * @return float */ function PMT(\$rate = 0, \$nper = 0, \$pv = 0, \$fv = 0, \$type = 0) { if (\$rate > 0) { return (-\$fv - \$pv * pow(1 + \$rate, \$nper)) / (1 + \$rate * \$type) / ((pow(1 + \$rate, \$nper) - 1) / \$rate); } else { return (-\$pv - \$fv) / \$nper; } }   \$rate = 10 / 1200; // rate = 10% \$nper = 60; // months \$pv = 1000; \$fv = 200;   \$payment = round(PMT(\$rate, \$nper, -\$pv, \$fv));```