PHPackages                             jesseschalken/set - 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. jesseschalken/set

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

jesseschalken/set
=================

java.utils.Set for PHP implementing ArrayAccess, Countable and IteratorAggregate with O(1) conversion to/from array keys

v1.0.2(10y ago)123.7k↓47.4%MITPHP

Since Jan 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/jesseschalken/php-set)[ Packagist](https://packagist.org/packages/jesseschalken/set)[ RSS](/packages/jesseschalken-set/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

php-set
=======

[](#php-set)

`java.utils.Set` for PHP implementing `ArrayAccess`, `Countable`, `IteratorAggregate` with *O(1)* conversion to/from array keys.

Uses `array_replace()`, `array_intersect_key()` and `array_diff_key()` for fast union, intersection and difference (`addAll()`, `retainAll()`, `removeAll()`).

```
use JesseSchalken\Set;

// Create a set from an array, Set or Traversable
$set = new Set([1, 2, 3]);
$set = new Set($set);
$set = new Set(new \ArrayIterator($set->toArray()));

// Add and remove elements
$set->add(4);
$set->remove(2);
var_export($set->contains(4)); // true
var_export($set->contains(2)); // false

// Clear and check if empty
$set->clear();
var_export($set->isEmpty()); // true

// Add and remove other arrays, Sets or Traversables
$set->addAll(['red', 'green', 'blue', 54]);
$set->removeAll(new \ArrayObject(['green', 54]));

// Check subset/superset
var_export($set->containsAll(new Set(['red', 'blue']))); // true
var_export($set->toArray()); // ['red', 'blue']

// Intersect another array, Set or Traversable
$set->retainAll(['blue', 'green']);
var_export($set->toArray()); // ['blue']
var_export($set->size()); // 1
var_export($set->equals(['blue'])); // true

// Convert to array keys
$set = new Set([1, 2]);
var_export($set->toArrayKeys()); // [1 => true, 2 => true]

// Convert from array keys
$set = Set::fromArrayKeys([7 => true, 3 => 'string']);
var_export($set->toArray()); // [7, 3]

// Use ArrayAccess
$set = new Set();
$set['red']   = true; // add
$set['green'] = true; // add
$set['red']   = false; // remove
var_export($set['green']); // true
var_export($set['blue']); // false
var_export($set['red']); // false

// Use IteratorAggregate
foreach ($set as $v) {
    var_export($v); // blue
}

// Use Countable
var_export(count($set)); // 1
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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

3

Last Release

3819d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1559204?v=4)[Jesse Schalken](/maintainers/jesseschalken)[@jesseschalken](https://github.com/jesseschalken)

---

Top Contributors

[![jesseschalken](https://avatars.githubusercontent.com/u/1559204?v=4)](https://github.com/jesseschalken "jesseschalken (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jesseschalken-set/health.svg)

```
[![Health](https://phpackages.com/badges/jesseschalken-set/health.svg)](https://phpackages.com/packages/jesseschalken-set)
```

###  Alternatives

[scribu/lib-posts-to-posts

A library for many-to-many relationships in WordPress

2281.0k1](/packages/scribu-lib-posts-to-posts)[shrink0r/monatic

Fiddling with the monad concept in php

245.3k2](/packages/shrink0r-monatic)

PHPackages © 2026

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