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

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

chipslays/collection
====================

Library for manipulating array as collection.

1.2.0(3y ago)01.2k1[1 PRs](https://github.com/chipslays/collection/pulls)14MITPHPCI passing

Since Jan 13Pushed 2w ago2 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (22)Used By (14)

📂 Collection
============

[](#-collection)

[![GitHub Workflow Status](https://camo.githubusercontent.com/21d348af54c7351760de2c6375776dd1fceacbdae08e4a86441b89cd93509dfb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63686970736c6179732f636f6c6c656374696f6e2f5465737473)](https://camo.githubusercontent.com/21d348af54c7351760de2c6375776dd1fceacbdae08e4a86441b89cd93509dfb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63686970736c6179732f636f6c6c656374696f6e2f5465737473)[![Packagist Version](https://camo.githubusercontent.com/d812f23e5c261e13affff9c7731d7db603a1c3c483b55bfabddbb680ddcf7566/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63686970736c6179732f636f6c6c656374696f6e)](https://camo.githubusercontent.com/d812f23e5c261e13affff9c7731d7db603a1c3c483b55bfabddbb680ddcf7566/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63686970736c6179732f636f6c6c656374696f6e)

Simple library for manipulating array or object as collection.

> ℹ Supported dot-notation and asterisks rules.

The purpose of this library is to provide a generic class for interacting with arrays of data. Convenient support for dot notation and asterisk keys.

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

[](#installation)

```
$ composer require chipslays/collection
```

Documentation
-------------

[](#documentation)

> Collection can created by helper function `collection()`.

#### `get(string $key [, $default = null, string $separator = '.'])`

[](#getstring-key--default--null-string-separator--)

Get item from collection by using dot notation.

```
use Chipslays\Collection\Collection;

$collection = new Collection([
    'user' => [
        'name' => 'chipslays',
    ],
]);

$name = $collection->get('user.name'); // chipslays
$email = $collection->get('user.email', 'default@email.com'); // default@email.com

$array = $collection->user; // array('name' => 'chipslays')
$name = $collection->user['name']; // chipslays
```

```
$collection = collection([
    'foo' => [
        'bar' => ['baz' => 1],
        'bam' => ['baz' => 2],
        'boo' => ['baz' => 3],
    ],
]);

$collection->get('foo.*.baz');
// Array
// (
//     [0] => 1
//     [1] => 2
//     [2] => 3
// )

$collection->get('foo.*');
// Array
// (
//     [0] => Array
//         (
//             [baz] => 1
//         )
//     [1] => Array
//         (
//             [baz] => 2
//         )
//     [2] => Array
//         (
//             [baz] => 3
//         )
// )
```

```
$collection = collection([
    'foo' => [
        'bar' => ['baz' => 1],
    ],
]);

$collection->get('foo.*.baz');
// 1

$collection->get('foo.*');
// Array
// (
//     [baz] => 1
// )
```

#### `set(string $key, $value = null [, string $separator = '.']): Collection`

[](#setstring-key-value--null--string-separator---collection)

Set/overwrite item in collection using by dot notation key.

```
use Chipslays\Collection\Collection;

$collection = new Collection([
    'user' => [
        'name' => 'chipslays',
    ],
]);

$collection->set('user.name', 'john doe');
$collection->set('user.email', 'john.doe@email.com');

$name = $collection->get('user.name'); // john doe
$email = $collection->get('user.email'); // john.doe@email.com
```

#### `has(string $key [, string $separator = '.']): bool`

[](#hasstring-key--string-separator---bool)

Check exists item in collection using by dot notation key.

```
use Chipslays\Collection\Collection;

$collection = new Collection([
    'user' => [
        'name' => 'chipslays',
    ],
]);

$hasName = $collection->has('user.name'); // true
$hasEmail = $collection->has('user.email'); // false
```

#### `first(): mixed`

[](#first-mixed)

Returns first item from collection.

```
use Chipslays\Collection\Collection;

$collection = new Collection(['foo', 'bar', 'baz']);

echo $collection->first(); // foo
```

#### `last(): mixed`

[](#last-mixed)

Returns last item from collection.

```
use Chipslays\Collection\Collection;

$collection = new Collection(['foo', 'bar', 'baz']);

echo $collection->last(); // baz
```

#### `shift(): mixed`

[](#shift-mixed)

Getting first item and remove her from collection.

```
use Chipslays\Collection\Collection;

$collection = new Collection(['foo', 'bar', 'baz']);

echo $collection->shift(); // foo
echo $collection->count(); // 2
```

#### `values(): Collection`

[](#values-collection)

Returns values without keys as collection.

```
use Chipslays\Collection\Collection;

$collection = new Collection(['color' => 'green', 'name' => 'apple']);

print_r($collection->values()); // collection(green, apple)
```

#### `keys(): Collection`

[](#keys-collection)

Returns keys without values as collection.

```
use Chipslays\Collection\Collection;

$collection = new Collection(['color' => 'green', 'name' => 'apple']);

print_r($collection->keys()); // collection(color, name)
```

#### `only(): Collection`

[](#only-collection)

Returns only selected keys.

```
use Chipslays\Collection\Collection;

$collection = new Collection(['color' => 'green', 'name' => 'apple']);

print_r($collection->only(['color'])); // collection(color => green)
```

#### `push(): Collection`

[](#push-collection)

#### `replace(): Collection`

[](#replace-collection)

#### `replaceRecursive(): Collection`

[](#replacerecursive-collection)

#### `merge(): Collection`

[](#merge-collection)

#### `mergeRecursive(): Collection`

[](#mergerecursive-collection)

#### `trim(): Collection`

[](#trim-collection)

#### `remove(...string $keys): Collection`

[](#removestring-keys-collection)

#### `limit(): Collection`

[](#limit-collection)

#### `chunk(int $size): Collection`

[](#chunkint-size-collection)

#### `each(callable $callback($item)): Collection`

[](#eachcallable-callbackitem-collection)

#### `map(callable $callback($item)): Collection`

[](#mapcallable-callbackitem-collection)

#### `mapWithKeys(callable $callback($item)): Collection`

[](#mapwithkeyscallable-callbackitem-collection)

#### `filter(callable $callback($item, $key) = null): Collection`

[](#filtercallable-callbackitem-key--null-collection)

#### `where($key, $operator = null, $value = null): Collection`

[](#wherekey-operator--null-value--null-collection)

#### `all(): array`

[](#all-array)

#### `collect(string $key, string $separator = '.')`

[](#collectstring-key-string-separator--)

#### `reverse(bool $preserveKeys)`

[](#reversebool-preservekeys)

#### `count(): int`

[](#count-int)

Get count of items in collection.

```
use Chipslays\Collection\Collection;

$collection = new Collection(range(1, 10));

echo $collection->count(); // 10
echo count($collection); // 10
```

#### `clear(): Collection`

[](#clear-collection)

Clear all items in collection.

```
use Chipslays\Collection\Collection;

$collection = new Collection(range(1, 10));

$collection->clear();
```

#### `toArray(): array`

[](#toarray-array)

Get collection items as array.

```
use Chipslays\Collection\Collection;

$collection = new Collection(range(1, 10));

$collection->toArray();
```

#### `toObject(): object`

[](#toobject-object)

Get collection items as object (stdClass).

```
use Chipslays\Collection\Collection;

$collection = new Collection(range(1, 10));

$collection->toObject();
```

#### `__toString(): string`

[](#__tostring-string)

Get items as printable string.

```
use Chipslays\Collection\Collection;

$collection = new Collection(['one', 'two']);

echo (string) $collection;

/** output string */
Array
(
    [0] => one
    [1] => two
)
```

👀 See also
----------

[](#-see-also)

- [`chipslays/array`](https://github.com/chipslays/array) - Simple library for array manipulate.

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance63

Regular maintenance activity

Popularity16

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% 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 ~34 days

Recently: every ~74 days

Total

20

Last Release

1296d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19103498?v=4)[chipslays](/maintainers/chipslays)[@chipslays](https://github.com/chipslays)

---

Top Contributors

[![chipslays](https://avatars.githubusercontent.com/u/19103498?v=4)](https://github.com/chipslays "chipslays (47 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

arrayarray-manipulationscollection

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mediawiki/semantic-cite

A Semantic MediaWiki extension to manage citation resources.

2310.2k1](/packages/mediawiki-semantic-cite)

PHPackages © 2026

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