PHPackages                             jmf/collection - 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. jmf/collection

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

jmf/collection
==============

Eases common operations with collections (arrays, iterables, etc).

1.2.0(3mo ago)055mitPHPPHP &gt;=8.3CI passing

Since Dec 15Pushed 3mo agoCompare

[ Source](https://github.com/jmfeurprier/collection)[ Packagist](https://packagist.org/packages/jmf/collection)[ RSS](/packages/jmf-collection/feed)WikiDiscussions 1.1 Synced 1mo ago

READMEChangelogDependencies (6)Versions (6)Used By (0)

Collection
==========

[](#collection)

Simple utilities to interact with collections (arrays, iterables, etc).

Installation
------------

[](#installation)

With composer:

```
composer require jmf/collection

```

Usage
-----

[](#usage)

### Retrieving a single item from a collection

[](#retrieving-a-single-item-from-a-collection)

When you need to retrieve the only value from a collection which **MUST** contain exactly one item:

```
use Jmf\Collection\Collection;

$array = ['foo'];

// Will return 'foo'
$item = Collection::one($array);

$array = ['foo', 'bar'];

// Will throw an exception
$item = Collection::one($array);

```

If the collection does not contain exactly one item, an exception will be thrown.

When you need to retrieve the only value from a collection which **CAN** contain exactly one item:

```
use Jmf\Collection\Collection;

$array = ['foo'];

// Will return 'foo'
$item = Collection::oneOrNull($array);

$array = ['foo', 'bar'];

// Will return null
$item = Collection::oneOrNull($array);

```

If the collection does not contain exactly one item, null is returned.

### Counting items in a collection

[](#counting-items-in-a-collection)

```
use Jmf\Collection\Collection;

$list = ['foo', 'bar', 'baz'];

// Will return 3
$count = Collection::count($list);

```

### Retrieving items from a nested array structure

[](#retrieving-items-from-a-nested-array-structure)

```
use Jmf\Collection\Collection;

$array = [
    'foo' => [
        'bar' => [
            'baz' => 'qux',
        ],
    ],
];

// Will return 'qux'
$item = Collection::deepGet($array, ['foo', 'bar', 'baz']);

```

### Testing item existence from a nested array structure

[](#testing-item-existence-from-a-nested-array-structure)

```
use Jmf\Collection\Collection;

$array = [
    'foo' => [
        'bar' => [
            'baz' => 'qux',
        ],
    ],
];

// Will return true
$exists = Collection::deepHas($array, ['foo', 'bar', 'baz']);

```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance78

Regular maintenance activity

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

Total

6

Last Release

116d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b08b8105ec8bc88d1c911e10dbf156814769650a67960e2f3d71ed6d2417f0d?d=identicon)[jmfeurprier](/maintainers/jmfeurprier)

---

Top Contributors

[![jmfeurprier](https://avatars.githubusercontent.com/u/8434690?v=4)](https://github.com/jmfeurprier "jmfeurprier (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jmf-collection/health.svg)

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

###  Alternatives

[baibaratsky/yii2-serialized-attributes-behavior

Yii2 Serialized Attributes Behavior

1174.1k9](/packages/baibaratsky-yii2-serialized-attributes-behavior)

PHPackages © 2026

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