cakephp/collection

Work easily with arrays and iterators by having a battery of utility traversal methods

Maintainers

👁 cakephp

Package info

github.com/cakephp/collection

Homepage

Issues

Forum

pkg:composer/cakephp/collection

Statistics

Installs: 10 071 097

Dependents: 16

Suggesters: 2

Stars: 90

5.4.0-RC1 2026-03-13 17:44 UTC

Requires

  • php: >=8.2

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 1adebf23647f79c6ccc745acfc1618c141b23384

collectionscakephparraysiterators

This package is auto-updated.

Last update: 2026-06-08 04:45:34 UTC


README

👁 Total Downloads
👁 License

CakePHP Collection Library

The collection classes provide a set of tools to manipulate arrays or Traversable objects. If you have ever used underscore.js, you have an idea of what you can expect from the collection classes.

Usage

Collections can be created using an array or Traversable object. A simple use of a Collection would be:

use Cake\Collection\Collection;

$items = ['a' => 1, 'b' => 2, 'c' => 3];
$collection = new Collection($items);

// Create a new collection containing elements
// with a value greater than one.
$overOne = $collection->filter(function ($value, $key, $iterator) {
 return $value > 1;
});

The Collection\CollectionTrait allows you to integrate collection-like features into any Traversable object you have in your application as well.

Documentation

Please make sure you check the official documentation