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

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

asko/collection
===============

A utility library for working with collections.

v1.0(2y ago)12041MITPHPPHP &gt;=8.2

Since Jun 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/askonomm/collection)[ Packagist](https://packagist.org/packages/asko/collection)[ RSS](/packages/asko-collection/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

Collection
==========

[](#collection)

[![codecov](https://camo.githubusercontent.com/fc5a56094e8e1cd96947cc9569d45dcf141433899165d419a9092aaa4bf61dea/68747470733a2f2f636f6465636f762e696f2f67682f61736b6f6e6f6d6d2f636f6c6c656374696f6e2f67726170682f62616467652e7376673f746f6b656e3d424951444f41474a4254)](https://codecov.io/gh/askonomm/collection)

A generic class that encapsulates a collection of items and provides helper methods to work with said collection.

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

[](#installation)

```
composer require asko/collection
```

Usage
-----

[](#usage)

Creating a new collection is as simple as creating a new Collection class instance and passing the constructor an array of items.

```
use Asko\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
```

### Available methods

[](#available-methods)

#### `push`

[](#push)

Add an item to the collection.

```
$collection->push(6);
```

#### `filter`

[](#filter)

Filter the collection using a callback.

```
$collection->filter(function ($item) {
    return $item > 3;
});
```

#### `map`

[](#map)

Map over the collection using a callback.

```
$collection->map(function ($item) {
    return $item * 2;
});
```

#### `any`

[](#any)

Check if any item in the collection passes a truth test.

```
$collection->any(function ($item) {
    return $item > 3;
});
```

#### `all`

[](#all)

Check if all items in the collection pass a truth test.

```
$collection->all(function ($item) {
    return $item > 3;
});
```

#### `each`

[](#each)

Iterate over the collection.

```
$collection->each(function ($item) {
    echo $item;
});
```

#### `reduce`

[](#reduce)

Reduce the collection to a single value.

```
$collection->reduce(function ($acc, $item) {
    return $acc + $item;
}, 0);
```

#### `first`

[](#first)

Get the first item in the collection.

```
$collection->first();
```

#### `last`

[](#last)

Get the last item in the collection.

```
$collection->last();
```

#### `avg`

[](#avg)

Get the average of the items in the collection by predicate

```
$collection->avg(function ($item) {
    return $item * 2;
});
```

#### `sum`

[](#sum)

Get the sum of the items in the collection by predicate

```
$collection->sum(function ($item) {
    return $item * 2;
});
```

#### `count`

[](#count)

Get the number of items in the collection.

```
$collection->count();
```

#### `toArray`

[](#toarray)

Get the collection as an array.

```
$collection->toArray();
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

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

Unknown

Total

1

Last Release

731d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17984167?v=4)[Alexey Skolyarov](/maintainers/asko)[@asko](https://github.com/asko)

---

Top Contributors

[![askonomm](https://avatars.githubusercontent.com/u/84135165?v=4)](https://github.com/askonomm "askonomm (10 commits)")

---

Tags

collectionsphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ip2location/ip2location-php

\[Official Release\] IP2Location PHP API to get location info from IPv4 and IPv6 address.

2154.1M37](/packages/ip2location-ip2location-php)[crell/attributeutils

A robust, flexible attribute handling framework

101485.0k10](/packages/crell-attributeutils)[workerman/statistics

3512.8k](/packages/workerman-statistics)[humaidem/filament-map-picker

5920.8k](/packages/humaidem-filament-map-picker)

PHPackages © 2026

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