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

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

palmtree/collection
===================

Immutable collections which provide commonly used functionality missing from arrays

v6.2.1(6mo ago)27.8k↓41.2%2MITPHPPHP &gt;=8.1CI passing

Since Aug 25Pushed 6mo ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (25)Used By (2)

🌴 Palmtree Collection
=====================

[](#palm_tree-palmtree-collection)

[![License](https://camo.githubusercontent.com/f5f59054fc2ef66ddef7b0540e065affbbf6668a856f5a9d83cce9dc3773e624/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f70616c6d747265652f636f6c6c656374696f6e2e737667)](LICENSE)[![Build](https://camo.githubusercontent.com/36d55e17ae895f0009b015631f911029ccb79cd680eaf144f11f6d1395d5c0ea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70616c6d747265657068702f636f6c6c656374696f6e2f6275696c642e79616d6c3f6272616e63683d6d6173746572)](https://github.com/palmtreephp/collection/actions/workflows/build.yaml)[![Packagist Version](https://camo.githubusercontent.com/559e82f8f438fb339ddcc151cb3130fec0f7257ef2e2659345ae22a141e1f588/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616c6d747265652f636f6c6c656374696f6e)](https://packagist.org/packages/palmtree/collection)

Immutable collections which provide commonly used functionality missing from arrays.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1

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

[](#installation)

Use composer to add the package to your dependencies:

```
composer require palmtree/collection
```

Usage
-----

[](#usage)

Collections can be used just like arrays for the most part. They implement [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess), [`Traversable`](https://www.php.net/manual/en/class.traversable) and [`Countable`](https://www.php.net/manual/en/class.countable):

```
use function Palmtree\Collection\c;

$collection = c(['foo' => 'bar', 'baz' => 'qux']);

$foo = $collection['foo'];
$collection['baz2'] = 'qux';

isset($collection['baz']); // true
unset($collection['baz']);
count($collection);

foreach ($collection as $key => $value) {
    // do stuff with value and/or key
}

// find returns the first matching element
$foo = $collection->find(fn ($v) => $v === 'bar');

// filter returns a new filtered collection
$quxCollection = $collection->filter(fn ($v) => $v === 'qux');
```

```
use function Palmtree\Collection\c;

$collection = c([1, 9, 5, 3, 7, 10])
    ->sort()
    ->filter(fn ($i) $i < 10)
    ->values()

// returns true as every element remaining in the collection is odd
$isAllOdd = $collection->every(fn ($i) => $i % 2 !== 0);
// returns false as it was removed in our filter
$collection->contains(10);

// returns true as at least one of the elements is false
c([true, true, false, true, true])->some(fn ($v) => !$v);
```

Many other methods are provided. Read through the documented [source code](src/Collection.php) to see more.

### Generics

[](#generics)

The library supports template annotations for use by static analysers such as Psalm and PHPStan:

```
/** @var Collection **/
$collection = new Collection();
$collection->add(new Foo());

foreach ($collection as $foo) {
    // Psalm/PHPStan and PhpStorm know that $foo is an instance of Foo here
}
```

License
-------

[](#license)

Released under the [MIT license](LICENSE)

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance66

Regular maintenance activity

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

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

Recently: every ~202 days

Total

21

Last Release

200d ago

Major Versions

v1.0.0 → v2.0.02018-09-11

v2.2.1 → v3.0.02021-02-17

v3.0.0 → v4.0.02021-02-21

v4.0.0 → v5.0.02021-05-09

v4.0.1 → v6.0.02023-08-13

PHP version history (6 changes)v1.0.0PHP &gt;=5.6

v2.0.0PHP &gt;=7.1

v4.0.0PHP &gt;=7.4

v5.0.5PHP ^7.4||^8.0

v6.0.0PHP ^8.1

v6.2.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/93cd57de0c03bc08173bbe424ce641b70b1bb9421f8d8fd474a33409a0f1644d?d=identicon)[palmtree](/maintainers/palmtree)

---

Top Contributors

[![andyexeter](https://avatars.githubusercontent.com/u/6660584?v=4)](https://github.com/andyexeter "andyexeter (171 commits)")

---

Tags

collectionphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[woutersioen/sir-trevor-php

A Sir Trevor to HTML conversion helper for PHP

2834.6k](/packages/woutersioen-sir-trevor-php)[naxon/laravel-url-uploaded-file

A package to leverage Laravel's UploadedFile functionality from URLs.

176.4k](/packages/naxon-laravel-url-uploaded-file)

PHPackages © 2026

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