PHP code example of nepster-web / php-mlm-matrix

1. Go to this page and download the library: Download nepster-web/php-mlm-matrix library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nepster-web / php-mlm-matrix example snippets


use Nepster\Matrix\Matrix;

$matrix = new Matrix(3, 2);

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

$matrix->toArray();

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));

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

$matrix->isFilled();

class MatrixService {

    public function findById(int $id): Matrix
    {
        // You need make a query to the `matrix` table that find the ng `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.
    }

}

$ php composer.phar 

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