PHPackages                             aa/array-diff - 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. aa/array-diff

ActiveLibrary

aa/array-diff
=============

Component for calculating difference of arrays

194PHP

Since Jan 24Pushed 7y ago2 watchersCompare

[ Source](https://github.com/a-ast/array-diff)[ Packagist](https://packagist.org/packages/aa/array-diff)[ RSS](/packages/aa-array-diff/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ArrayDiff Calculator
====================

[](#arraydiff-calculator)

[![SensioLabsInsight](https://camo.githubusercontent.com/ae31a121fdea6ce74050fc8c0ede9df794b17a4b90c750a88b44162247afb094/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30306465323364662d623837662d346261622d393332322d6637393463616433333366632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/00de23df-b87f-4bab-9322-f794cad333fc)

ArrayDiff Calculator works similar to a php function `array_diff_assoc`but calculates a difference of arrays in a better way due to:

- using expressions (value matching),
- providing extended information about an array difference.

**Example**

```
$array1 = ['a' => 8, 'b' => 2, 'c' => 3];
$array2 = ['a' => 6, 'b' => 2, 'd' => 3];

$calc = new Calculator(new SimpleMatcher());
$diff = $calc->calculateDiff($array1, $array2);

print $diff->toString();
```

outputs:

```
missing:
    -
        key_path: c
        expected: 3
unmatched:
    -
        key_path: a
        expected: 8
        actual: 6
```

because

- Item with the key 'c' is **missing** in array2
- Items with key 'a' have different values (**unmatched**)

**Advanced example**

Let's assume we have two arrays:

```
$array1 = [
    'name'     => '',
    'price'    => ' ',
    'in_stock' => '',
    'isbns'    => [
        'isbn-10' => '',
    ],
    'pages'    => '',
];
```

```
$array2 = [
    'name'     => 'The Lord of the Rings',
    'price'    => '25.99 EUR',
    'in_stock' => true,
    'isbns'    => [
        'isbn-10' => '1230260002385',
    ],
    'pages'    => 567,
];
```

 You can calculate a difference of these arrays using an expression matching:

```
$calc = new Calculator(new ExpressionMatcher());
$diff = $calc->calculateDiff($array1, $array2);

print $diff->toString();
```

It returns:

```
missing: {  }
unmatched:
    -
        key_path: pages
        expected: ''
        actual: 567
```

because

- keys of array1 match keys of array2, so there are no missing items
- string 'The Lord of the Rings' matches the expression ``
- '25.99 EUR' matches the compound expression ` `
- 'true' matches the expression ``
- isbn value '1230260002385' matches the expression ``
- page count '567' **doesn't match** the expression ``

Expressions have syntax ``.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0838477bd5a8b5ea070b5779c0595de0c34860cb3d77599ff8274138f145f060?d=identicon)[AAstakhov](/maintainers/AAstakhov)

---

Top Contributors

[![a-ast](https://avatars.githubusercontent.com/u/6177375?v=4)](https://github.com/a-ast "a-ast (20 commits)")

### Embed Badge

![Health badge](/badges/aa-array-diff/health.svg)

```
[![Health](https://phpackages.com/badges/aa-array-diff/health.svg)](https://phpackages.com/packages/aa-array-diff)
```

PHPackages © 2026

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