PHPackages                             nepster-web/php-mlm-matrix - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. nepster-web/php-mlm-matrix

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nepster-web/php-mlm-matrix
==========================

Library for working with mlm matrices

v1.0.0(7y ago)5979248[2 issues](https://github.com/nepster-web/php-mlm-matrix/issues)MITPHPPHP &gt;=7.2

Since Mar 5Pushed 7y ago13 watchersCompare

[ Source](https://github.com/nepster-web/php-mlm-matrix)[ Packagist](https://packagist.org/packages/nepster-web/php-mlm-matrix)[ RSS](/packages/nepster-web-php-mlm-matrix/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

MLM Matrix
==========

[](#mlm-matrix)

[![Latest Version](https://camo.githubusercontent.com/18c69d0bb7d63219ae18b937a13aa2c24f12c827e1f4ba9a648e5bcf8d670d47/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6e6570737465722d7765622f7068702d6d6c6d2d6d61747269782e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://github.com/nepster-web/php-mlm-matrix)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/4fc72544fa63b87d22674e3af816d4c38adb289fac4732df4ed6728fcff5948d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6570737465722d7765622f7068702d6d6c6d2d6d61747269782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nepster-web/php-mlm-matrix)

Library for working with MLM matrices.

Did you find an error?
----------------------

[](#did-you-find-an-error)

If you found an error in the code or grammatical mistake or any inaccuracy, please create [new issues](https://github.com/nepster-web/php-mlm-matrix/issues/new).

What is the MLM matrix?
-----------------------

[](#what-is-the-mlm-matrix)

Among the many MLM compensation plans available today, the Matrix plan is among the most popularly recommended owing to its uncomplicated structure. As it is quite simple in understanding it is considered very useful and resourceful and can be easily integrated into the MLM business.

To understand the Matrix plan, it makes sense to first understand its structure. The matrix
has fixed numbers of rows and columns, organizing the numbers in a particular width and depth. Typically, most MLM Matrix plans follow two types of structures; 2x2 or the 3x3, but there are exceptions based on company requirements. All the members in a Matrix Plan are positioned serially from top to bottom or left to right.

[![demo](./doc/images/view.png)](./doc/images/view.png)

After the matrix is filled, user at level 1 receives a reward and the matrix itself is divided into several matrices (depends on matrix pow, for example the cubic matrix will be divided into 3 new matrices). After that, new matrices wait for filling and cycle is repeated.

Install
-------

[](#install)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ php composer.phar require --prefer-dist nepster-web/php-mlm-matrix "*"

```

or add

```
"nepster-web/php-mlm-matrix": "*"

```

to the `require` section of your `composer.json` file.

Structure
---------

[](#structure)

- `demo` - Library demo
- `doc` - Documentation files for GitHub
- `shema` - Sample database table schema (MySQL)
- `src` - Main library code
- `tests` - Unit tests

Usage
-----

[](#usage)

Creating a new matrix object:

```
use Nepster\Matrix\Matrix;

$matrix = new Matrix(3, 2);
```

Getting information about the matrix:

```
$matrix->getDepth();
$matrix->getPow();
```

Get matrix array:

```
$matrix->toArray();
```

Managing users in the matrix:

```
use Nepster\Matrix\Coord;
use Nepster\Matrix\Matrix;

$matrix = new Matrix(3, 2);

$matrix->addTenant(null, function() {
    // return your user data
})

$matrix->addTenant(new Coord(1, 1), function() {
    // return your user data
})

$matrix->hasTenant(new Coord(0, 0));
$matrix->hasTenant(new Coord(1, 1));

$matrix->removeTenant(new Coord(1, 1));
```

Check the correctness of coordinates:

```
$matrix->isValidCoord(new Coord(0, 0));
```

Check if there are free positions in the matrix:

```
$matrix->isFilled();
```

[For more examples, see the demo file.](./demo/index.php)

How can I use database for matrices?
------------------------------------

[](#how-can-i-use-database-for-matrices)

Based on the different specifics of mlm projects and web development tools, this library implements only the algorithm of operation of mlm matrices without storage support.

However, if you works with the database you can easily implement keeping and restore of matrix objects. You can study the example in the file [MySQL schema](shema/matrix.sql).

For example, create a new service that allows you to write and/or restore the matrix object from the database:

```
class MatrixService {

    public function findById(int $id): Matrix
    {
        // You need make a query to the `matrix` table that find the required record
        // Use join or another query to retrieve user data from the `matrix_users` table
        // Initialize new Matrix object
        // Using `addTenant` method that add users to Matrix object (based on data from `matrix_users` table)
        // Return the proper Matrix object
    }

    public function save(Matrix $matrix): void
    {
        // Get the matrix array using the `$matrix->toArray()` method
        // Create a valid request to save data to the database
        // - Most likely in a relational database you will have 2 tables (matrices and matrix_users)
        // - Don`t forget to check a new matrix is being created or edited an already existing matrix

        // Note1: Write down users with depth and number for further recovery
        // Note2: Don`t write coordinates with empty positions to the database.
    }

}
```

Testing
-------

[](#testing)

`$ phpunit`

or

`$ vendor/bin/phpunit`

License
-------

[](#license)

This library is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~1347 days

Total

2

Last Release

2735d ago

Major Versions

v0.0.1 → v1.0.02018-11-11

PHP version history (2 changes)v0.0.1PHP &gt;=5.3.1

v1.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3afe1904e4ddaf0b5c2a46403167d059a74feec4a78644ba19a11eadb8f6bbe?d=identicon)[nepster-web](/maintainers/nepster-web)

---

Top Contributors

[![nepster-web](https://avatars.githubusercontent.com/u/5681979?v=4)](https://github.com/nepster-web "nepster-web (45 commits)")

---

Tags

mlmmlm-matrixnetwork-marketingphpphp7mlm matrixnetwork marketingmlm marketing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nepster-web-php-mlm-matrix/health.svg)

```
[![Health](https://phpackages.com/badges/nepster-web-php-mlm-matrix/health.svg)](https://phpackages.com/packages/nepster-web-php-mlm-matrix)
```

###  Alternatives

[ctidigital/magento2-configurator

Keep magento persistently configured using files

174317.4k](/packages/ctidigital-magento2-configurator)[comcast/php-legal-licenses

A utility to generate a Licenses file containing the full license text for every dependency in your project for legal purposes.

821.1M9](/packages/comcast-php-legal-licenses)[xfra35/f3-cron

Job scheduling for the PHP Fat-Free Framework

73107.5k](/packages/xfra35-f3-cron)[bagusindrayana/laravel-coordinate

get nearby location from eloquent laravel

3019.7k](/packages/bagusindrayana-laravel-coordinate)

PHPackages © 2026

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