PHPackages                             pqrs/phploan - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. pqrs/phploan

ActiveLibrary[Payment Processing](/categories/payments)

pqrs/phploan
============

Calculates the monthly repayments of a loan

13.5kPHP

Since Feb 13Pushed 8y ago2 watchersCompare

[ Source](https://github.com/pqrs/phploan)[ Packagist](https://packagist.org/packages/pqrs/phploan)[ RSS](/packages/pqrs-phploan/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHPLoan
=======

[](#phploan)

Provides some functions to:

- Calculate the amount of every monthly payment based on the loan principal, interest rate and number of payments.
- Calculate the loan principal based on the number of payments, interest rate and payment amount.
- Calculate the number of payments based on the principal, interest rate and payment amount.

Also provides a method to return the loan payment schedule.

Installation
------------

[](#installation)

```
composer require pqrs/phploan=dev-master

```

Alternatively, add the dependency directly to your composer.json file:

```
"require": {
    "pqrs/phploan": "dev-master"
}

```

Then add to your php code:

```
require_once __DIR__ . '/vendor/autoload.php';   // Autoload files using Composer autoload

use PHPLoan\Loan;

```

Usage
-----

[](#usage)

```
Variables nomenclature

$P    Principal (loan amount)
$r    Annual interest rate
$n    Number of payments (months)
$A    Monthly payment amount

```

### method calculateMonthlyPayment( $P, $r, $n )

[](#method-calculatemonthlypayment-p-r-n-)

Calculates the amount of every monthly payment based on the loan principal, interest rate and number of payments.

```
$loan = new Loan;

$result = $loan->calculateMonthlyPayment( 60000 , 9, 360 );
echo number_format($result, 2, ".", ",") . PHP_EOL;

// Prints 482.77

```

### method calculatePrincipal( $n, $r, $A )

[](#method-calculateprincipal-n-r-a-)

Calculates the loan principal based on the number of payments, interest rate and payment amount.

```
$loan = new Loan;

$result = $loan->calculatePrincipal( 360, 9, 482.77357 );
echo number_format($result, 2, ".", ",") . PHP_EOL;

// Prints 60,000.00

```

### method calculateNumPayments( $P, $r, $A )

[](#method-calculatenumpayments-p-r-a-)

Calculates the number of payments based on the principal, interest rate and payment amount.

```
$loan = new Loan;

$result = $loan->calculateNumPayments( 60000, 9, 482.77357 );
echo $result . PHP_EOL;

// Prints 360

```

### method getSchedule( $P, $r, $n )

[](#method-getschedule-p-r-n-)

Returns an object with the loan payment schedule.

```
$loan = new Loan;

$schedule = $loan->getSchedule( 60000, 9, 12 );

echo "";

foreach ($schedule as $key) {
    echo "";
    echo "" . $key->numpayment  . "";
    echo "" . $key->payment     . "";
    echo "" . $key->interest    . "";
    echo "" . $key->principal   . "";
    echo "" . $key->balance     . "";
    echo "";
}

echo "";

// Prints html table:
// 1   5,247.09    450.00  4,797.09    55,202.91
// 2   5,247.09    414.02  4,833.07    50,369.84
// 3   5,247.09    377.77  4,869.31    45,500.53
// 4   5,247.09    341.25  4,905.83    40,594.70
// 5   5,247.09    304.46  4,942.63    35,652.07
// 6   5,247.09    267.39  4,979.70    30,672.37
// 7   5,247.09    230.04  5,017.05    25,655.32
// 8   5,247.09    192.41  5,054.67    20,600.65
// 9   5,247.09    154.50  5,092.58    15,508.07
// 10  5,247.09    116.31  5,130.78    10,377.29
// 11  5,247.09    77.83   5,169.26    5,208.03
// 12  5,247.09    39.06   5,208.03    0.00

```

Examples
--------

[](#examples)

You can find some uses for these functions in [tests folder](tests).

Prerequisites
-------------

[](#prerequisites)

PHP &gt; 5.6

Not tested, but if you want to use phploan in 5.x PHP versions lower than 5.6, probably the only thing you have to change is the use of exponential expressions in [Loan.php](src/PHPLoan/Loan.php). Change \*\* for the function **pow()**:

```
// In method calculateMonthlyPayment( $P , $r, $n )

    $A = $P * (( $i * pow((1 + $i), $n) ) / ( pow((1 + $i), $n) - 1 ));

// In method calculatePrincipal( $n, $r, $A )

    $P = $A * ( pow((1 + $i), $n) - 1 ) / ( $i * (pow((1 + $i), $n) ));

```

Contributing
------------

[](#contributing)

Contributions are very welcome!

Credits
-------

[](#credits)

**Copyright © 2018 Alvaro Piqueras** - [pqrs](https://github.com/pqrs)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1423685?v=4)[alvaro](/maintainers/pqrs)[@pqrs](https://github.com/pqrs)

---

Tags

capitalinterestinterest-ratesloanloan-paymentsloanspaymentphpprincipal

### Embed Badge

![Health badge](/badges/pqrs-phploan/health.svg)

```
[![Health](https://phpackages.com/badges/pqrs-phploan/health.svg)](https://phpackages.com/packages/pqrs-phploan)
```

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
