PHPackages                             hgato/php-crud-comparator - 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. hgato/php-crud-comparator

ActiveLibrary

hgato/php-crud-comparator
=========================

Library to compare PHP model arrays

v1.0.5(3y ago)045MITPHPPHP &gt;=7.0.33

Since Mar 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hgato/hgato-php-crud-comparator)[ Packagist](https://packagist.org/packages/hgato/php-crud-comparator)[ RSS](/packages/hgato-php-crud-comparator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)DependenciesVersions (8)Used By (0)

CRUD Comparator
===============

[](#crud-comparator)

This library is meant to compare arrays of models and return 3 arrays: to create, to update, to delete.

Logic of execution is following:

- array of old models is provided as a first argument
- array of new models is provided as a second argument
- array of id fields is provided as the third argument
- array of secondary fields is provided as fourth argument
- if the model with same ids (all id fields treated as combined key) exists in both old and new array but secondary fields are different - model is treated as one for update
- if the model with same ids exists in both old and new array and secondary fields are same - model is ignored
- if model is in old array but not in new - model is meant to be deleted
- im model vice versa in noe, but not in old - model is meant for creation

Typical use case: frontend sends an array of models, but doesn't say what have changed. Simultaneously some data is in database already. This library helps to fund difference.

Example
-------

[](#example)

```
class TestObject
{
  public $id;
  public $key;
  public $name;
  public $description;
}

$oldArray = [/* Some instances of TestObject*/];
$newArray = [/* Other instances of TestObject*/];

$comparator = new ObjectComparator();
$comparator->compare(
    $oldArray,
    $newArray,
    ['id', 'key'],
    ['name', 'description']
);

$create = $comparator->getCreate();
$update = $comparator->getUpdate();
$delete = $comparator->getDelete();
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Total

6

Last Release

1161d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4870cc9f392bd965b133af2d3bed1d6753c584085f53e70ff0fd4181e6f370e7?d=identicon)[hgato](/maintainers/hgato)

---

Top Contributors

[![hgato](https://avatars.githubusercontent.com/u/28675954?v=4)](https://github.com/hgato "hgato (11 commits)")

### Embed Badge

![Health badge](/badges/hgato-php-crud-comparator/health.svg)

```
[![Health](https://phpackages.com/badges/hgato-php-crud-comparator/health.svg)](https://phpackages.com/packages/hgato-php-crud-comparator)
```

PHPackages © 2026

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