PHPackages                             ajthenewguy/php7-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. ajthenewguy/php7-matrix

ActiveLibrary

ajthenewguy/php7-matrix
=======================

A Matrix class leveraging PHP7 data strucures

v2.0.0(5y ago)04MITPHPPHP ^7.2.5

Since May 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/fissible/php7-matrix)[ Packagist](https://packagist.org/packages/ajthenewguy/php7-matrix)[ RSS](/packages/ajthenewguy-php7-matrix/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (5)Used By (0)

php7-matrix
===========

[](#php7-matrix)

PHP Matrix leveraging PHP7 data structures.

Usage
-----

[](#usage)

Instances can be instantiated with data, passing in an array of arrays. The first array should be the rows, the members of each being the column/cell values.

### Instantiation

[](#instantiation)

```
use Matrix\Matrix;

$Matrix = new Matrix([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]);

// Create a 3x3 matrix filled with 1's.

$Matrix = Matrix::create($width = 3, $height = 3, 1);

// Create a 5x5 identity matrix.

$Matrix = Matrix::identity(5);

```

### Non-Mutative Instance Methods

[](#non-mutative-instance-methods)

```
public added($input): Matrix

```

Return a new matrix with a matrix or numeric value added to this instance.

```
public determinant(): numeric

```

Scalar value that can be computed from the elements of a square matrix.

```
public divided($input): Matrix

```

Return a new matrix divided by a matrix or numeric value.

```
public equals(Matrix $m): bool

```

Check if the matrix equals the suppled matrix.

```
public exponentiated($input): Matrix

```

Returns a new matrix exponentiated by a numeric value.

```
public get(int $x_column, int $y_row)

```

Get the value at the given coordinates/offsets; 0-based index.

```
public getAdjugate(): Matrix

```

Get the ajugate/adjoint of the matrix, which is the transpose of its cofactor matrix.

```
public getAntidiagonal(): Vector

```

Get a Vector of the diagonal going from the lower left corner to the upper right corner.

```
public getCofactors(): Matrix

```

Return new Matrix of the cofactors of all components.

```
public getColumn(int $offset): Vector

```

Returns a Vector representing the column at the given offset.

```
public getData(): Vector

```

Get the inner Vector that holds the matrix data.

```
public getDiagonal(): Vector

```

Get a Vector of the diagonal components.

```
public getInverse(): Matrix

```

Return new Matrix of this Matrix's inverse

```
public getMinors(int $column_x, int $row_y = 0): Matrix

```

Get a Matrix of the minors of this Matrix for the given column/row.

```
public getNegative(): Matrix

```

Get a Matrix of the negative of this Matrix.

```
public getRow(int $y): Vector

```

Returns a Vector representing the row at the given offset.

```
public getTranspose(): Matrix

```

Get a Matrix with the components of this Matrix flipped along the diagonal.

```
public isDiagonal(): bool

```

Check if the matrix is a diagonal matrix, a matrix in which the entries outside the main diagonal are all zero.

```
public isTriangular(): bool

```

Check if the matrix is triangular, a matrix that is either upper or lower triangular.

```
public isLowerTriangular(): bool

```

Check if all the entries above the main diagonal are zero.

```
public isUpperTriangular(): bool

```

Check if all the entries below the main diagonal are zero.

```
public isInvertible(): bool

```

Check if this Matrix is invertible, a matrix where the determinant is non-zero.

```
public isSquare(): bool

```

Check if the matrix has the same number of rows and columns.

```
public isSymmetric(): bool

```

Check if the matrix equals its transpose.

```
public isSkewSymmetric(): bool

```

Check if the matrix transpose equals its negative.

```
public map(callable $callback): Matrix

```

Return a matrix with a callback applied to each component of this matrix.

```
public mapMatrix(Matrix $matrix, callable $callback, $validation = self::SAME): Matrix

```

Return a matrix with a callback applied to each component of this matrix, passing in a cooresponding value from a supplied Matrix.

```
public multiplied($input): Matrix

```

Return a new matrix with a matrix or value multiplied from this instance.

```
public subtracted($input): Matrix

```

Return a new matrix with a matrix or value subtracted from this instance.

```
public toArray(): array

```

Return an array representation of the Matrix data.

```
public trace()

```

Get the sum of the diagonal.

### Mutative Instance Methods

[](#mutative-instance-methods)

```
public add($input): Matrix

```

Add a matrix or numeric value to the matrix.

```
public apply(callable $callback): Matrix

```

Apply a callback to each component of the Matrix.

```
public applyMatrix(Matrix $matrix, callable $callback, $validation = self::SAME): Matrix

```

Apply a callback to each component of the Matrix, passing in a cooresponding value from a supplied Matrix.

```
public divide($input): Matrix

```

Divide this matrix by a matrix or numeric value.

```
public exponential($input): Matrix

```

Exponentiate this matrix by a numeric value.

```
public inverse(): Matrix

```

Update this matrix to its inverse.

```
public multiply($input): Matrix

```

Multiply a matrix or value to this instance.

```
public set(int $x_column, int $y_row, $value): void

```

Set the value at the given coordinates/offsets; 0-based index.

```
public setData(iterable $table = []): Matrix

```

Set the inner data Vector.

```
public subtract($input): Matrix

```

Subtract a matrix or value to this instance.

```
public transpose(): Matrix

```

Flip the Matrix along the diagonal.

Matrix Mapping Algorithm
------------------------

[](#matrix-mapping-algorithm)

When mapping one matrix to another, their dimensions must match exactly or must reflect (transposed dimensions). Either the column counts and row counts must match or the row count of one must match the column count of the other.

### Example: Matrix-&gt;multiply(Matrix)

[](#example-matrix-multiplymatrix)

Matrix A:

```
[1, 2, 3]
[4, 5, 6]

```

Matrix B:

```
[7, 8]
[9, 10]
[11, 12]

```

Expected:

```
[ 58,  64]
[139, 154]

```

STEP 1 - 1×7:

```
A:             B:
[1, -, -] x [7, -]
[-, -, -]   [-, -]
            [-, -]

```

STEP 2 - 2×9:

```
A:             B:
[-, 2, -] x [-, -]
[-, -, -]   [9, -]
            [-, -]

```

STEP 3 - 3×11:

```
A:             B:
[-, -, 3] x [ -, -]
[-, -, -]   [ -, -]
            [11, -]

```

STEP 4 - Sum the products:

```
C:
[58, -]
[ -, -]

```

STEP 5 - 1×8:

```
A:             B:
[1, -, -] x [-, 8]
[-, -, -]   [-, -]
            [-, -]

```

STEP 6 - 2×10:

```
A:             B:
[-, 2, -] x [-,  -]
[-, -, -]   [-, 10]
            [-,  -]

```

STEP 7 - 3×12:

```
A:             B:
[-, -, 3] x [-,  -]
[-, -, -]   [-,  -]
            [-, 12]

```

STEP 8 - Sum the products:

```
C:
[58, 64]
[ -, -]

```

STEP 9 - 4×7:

```
A:             B:
[-, -, -] x [7, -]
[4, -, -]   [-, -]
            [-, -]

```

STEP 10 - 5×9:

```
A:             B:
[-, -, -] x [-, -]
[-, 5, -]   [9, -]
            [-, -]

```

STEP 11 - 6×11:

```
A:             B:
[-, -, -] x [-,  -]
[-, -, 6]   [-,  -]
            [11, -]

```

STEP 12 - Sum the products:

```
C:
[ 58, 64]
[139,  -]

```

STEP 13 - 4×8:

```
A:             B:
[-, -, -] x [-, 8]
[4, -, -]   [-, -]
            [-, -]

```

STEP 14 - 5×10:

```
A:             B:
[-, -, -] x [-,  -]
[-, 5, -]   [-, 10]
            [-,  -]

```

STEP 15 - 6×12:

```
A:             B:
[-, -, -] x [-,  -]
[-, -, 6]   [-,  -]
            [-, 12]

```

STEP 16 - Sum the products:

```
C:
[ 58,  64]
[139, 154]

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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 ~2 days

Total

4

Last Release

2169d ago

Major Versions

v1.0.2 → v2.0.02020-06-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef298fbffac2225e36ab3a6e089af020f76885bc65d5f6afda831c64939e1e4b?d=identicon)[fissible](/maintainers/fissible)

---

Top Contributors

[![fissible](https://avatars.githubusercontent.com/u/1410914?v=4)](https://github.com/fissible "fissible (13 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ajthenewguy-php7-matrix/health.svg)

```
[![Health](https://phpackages.com/badges/ajthenewguy-php7-matrix/health.svg)](https://phpackages.com/packages/ajthenewguy-php7-matrix)
```

###  Alternatives

[malios/php-to-ascii-table

A PHP library to generate plain text tables.

30118.8k1](/packages/malios-php-to-ascii-table)[devium/toml

A PHP encoder/decoder for TOML compatible with specification 1.0.0

3968.9k12](/packages/devium-toml)[samsara/fermat

A library providing math and statistics operations for numbers of arbitrary size.

653.1k3](/packages/samsara-fermat)[hardcastle/xrpl_php

PHP SDK / Client for the XRP Ledger

129.7k5](/packages/hardcastle-xrpl-php)

PHPackages © 2026

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