PHPackages                             abbasghasemi/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. [Queues &amp; Workers](/categories/queues)
4. /
5. abbasghasemi/collection

ActiveLibrary[Queues &amp; Workers](/categories/queues)

abbasghasemi/collection
=======================

A collection of complete tools for working with PHP arrays.

1.6(1y ago)0201MITPHPPHP ^8.1

Since Aug 17Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)DependenciesVersions (4)Used By (1)

abbasghasemi/collection
=======================

[](#abbasghasemicollection)

 **A PHP library for work with arrays**

Powerful
--------

[](#powerful)

- Support List, Map, Set, Stack, Queue, Object ...
- Functional (indexOf, map, where, reduce, first, firstOrNull firstWhere, ...)
- Type generic documentation
- Collections class for generate &amp; filled List `Collections::filled(int $length, mixed $element)`
- The ability to enforce maps and lists to accept a specific type

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

[](#installation)

The preferred of installation is via [Composer](https://getcomposer.org). Run the following command to install the package and add it as a requirement to your project's `composer.json`:

```
composer require abbasghasemi/collection
```

Array example
-------------

[](#array-example)

```
$list = Collections::filled(10, 'filled'); // ArrayList
echo count($list); // 10
echo Collections::toArraySet($list)->size(); // 1
$list->add(1); // This method does not exist!
echo $list->first(); // filled

$list = new MutableArrayList(/*[default]*/type: 'int');
$list->add(1); // added
$list->add(5); // added
echo count($list); // 2
echo $list->indexOf(1); // 0
echo $list->indexOf(6); // -1

$list = Collections::generate(10, function ($index){
    return $index;
}); // ArrayList
$list = $list->where(function ($element){
    return $element % 2 === 0;
});
echo $list->last(); // 8
echo $list; // [0,2,4,6,8]
```

Map example
-----------

[](#map-example)

```
$map = new MutableInsensitiveMap();
$map['InSensitive'] = 'Insensitive';
$map['INSENSITIVE'] = 'Insensitive';
echo $map['insensitive']; // Insensitive
echo $map->size(); // 1

$object = new MutableArrayList(); // or other object
$map2 = new MutableObjectMap(keyType: $object::class, valueType: $map::class);
$map2[$object] = $map;

echo intval($map2[$object] === $map); // 1

$map2->values()->first()['INSENSITIVE'] = 10;
echo $map['InSensitive']; // 10
$map2->keys()->first()->add('first');
$map2->keys()->first()->add('last');

echo $object->join(','); // first,last
```

Arrays class
------------

[](#arrays-class)

ClassArrayListMutableArrayListArraySetMutableArraySetEditable❌✅❌✅Repeatable✅✅❌❌Iterator✅✅✅✅Countable✅✅✅✅Class methods
-------------

[](#class-methods)

MethodArrayListMutableArrayListArraySetMutableArraySetforward✅✅✅✅back✅✅✅✅size✅✅✅✅isEmpty✅✅✅✅isNotEmpty✅✅✅✅contains✅✅✅✅toArray✅✅✅✅forEach✅✅✅✅first✅✅✅✅firstOrNull✅✅✅✅last✅✅✅✅lastOrNull✅✅✅✅get✅✅✅✅getRange✅✅✅✅take✅✅✅✅firstWhere✅✅✅✅where✅✅✅✅lastWhere✅✅✅✅reduce✅✅✅✅indexOf✅✅✅✅lastIndexOf✅✅✅✅indexWhere✅✅✅✅lastIndexWhere✅✅✅✅join✅✅✅✅fillRange❌✅❌❌update❌✅❌✅reversed❌✅❌✅shuffle❌✅❌✅add❌✅❌✅addAll❌✅❌✅insert❌✅❌✅insertAll❌✅❌✅remove❌✅❌✅removeFirst❌✅❌✅removeLast❌✅❌✅removeRange❌✅❌✅removeWhere❌✅❌✅sort❌✅❌✅clear❌✅❌✅Maps class
----------

[](#maps-class)

ClassStringMapMutableStringMapInsensitiveMapMutableInsensitiveMapObjectMapMutableObjectMapEditable❌✅❌✅❌✅Repeatable✅✅✅✅✅✅Iterator✅✅✅✅✅✅Countable✅✅✅✅✅✅Insensitive❌❌✅✅--Object key❌❌❌❌✅✅Class methods
-------------

[](#class-methods-1)

MethodStringMapMutableStringMapInsensitiveMapMutableInsensitiveMapObjectMapMutableObjectMapsize✅✅✅✅✅✅isEmpty✅✅✅✅✅✅isNotEmpty✅✅✅✅✅✅forEach✅✅✅✅✅✅containsKey✅✅✅✅✅✅containsValue✅✅✅✅✅✅keys✅✅✅✅✅✅values✅✅✅✅✅✅mutableValues✅✅✅✅✅✅entries✅✅✅✅✅✅entryKey✅✅✅✅✅✅get✅✅✅✅✅✅*get syntax* \[key\]✅✅✅✅✅✅toMap✅✅✅✅❌❌put❌✅❌✅❌✅*set syntax* \[key\] = value❌✅❌✅❌✅putIfAbsent❌✅❌✅❌✅putAll❌✅❌✅❌✅update❌✅❌✅❌✅updateKey❌✅❌✅❌✅replace❌✅❌✅❌✅merge❌✅❌✅❌✅remove❌✅❌✅❌✅removeWhere❌✅❌✅❌✅Collections class
-----------------

[](#collections-class)

Static methodDescriptionfilled`Collections::filled(int $length, mixed $element, ?string $type = null): ArrayList`generate`Collections::generate(int $length, callback $callback, ?string $type = null): ArrayList`of`Collections::of(mixed ...$elements): ArrayList`typeOf`Collections::typeOf(string $type, mixed ...$elements): ArrayList`mutableFilled`Collections::filled(int $length, mixed $element, ?string $type = null): MutableArrayList`mutableGenerate`Collections::generate(int $length, callback $callback, ?string $type = null): MutableArrayList`mutableOf`Collections::of(mixed ...$elements): MutableArrayList`mutableTypeOf`Collections::mutableTypeOf(string $type, mixed ...$elements): MutableArrayList`toArrayList`Collections::toArrayList(Collection $collection): ArrayList`toMutableArrayList`Collections::toMutableArrayList(Collection $collection): MutableArrayList`toArraySet`Collections::toArraySet(Collection $collection): ArraySet`toMutableArraySet`Collections::toMutableArraySet(Collection $collection): MutableArraySet`sortAscending`Collections::sortAscending(MutableCollection $collection): void`sortDescending`Collections::sortDescending(MutableCollection $collection): void`equals`Collections::equals(?ObjectC $a, ?ObjectC $b): bool`hashCode`Collections::hashCode(mixed $value): int`toString`Collections::toString(mixed $value): string`See also easy-data-model
------------------------

[](#see-also-easy-data-model)

[Creates a data model from array data.](https://github.com/abbasghasemi/easy-data-model)

Author &amp; support
--------------------

[](#author--support)

This library was created by [Abbas Ghasemi](https://farasource.com/).

You can report issues at the [GitHub Issue Tracker](https://github.com/abbasghasemi/collection/issues).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

629d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bfce46e4151cf4ef307121ac3ae246cb786885f7a5d49a2a571f866b6a11a3b?d=identicon)[abbasghasemi](/maintainers/abbasghasemi)

---

Top Contributors

[![abbasghasemi](https://avatars.githubusercontent.com/u/51255667?v=4)](https://github.com/abbasghasemi "abbasghasemi (3 commits)")

---

Tags

queueserializablestackmapsetcollectionlistimmutablearraylistmutable

### Embed Badge

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

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

###  Alternatives

[ramsey/collection

A PHP library for representing and manipulating collections.

1.2k486.0M69](/packages/ramsey-collection)[phootwork/collection

The phootwork library fills gaps in the php language and provides better solutions than the existing ones php offers.

3924.8M15](/packages/phootwork-collection)[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.0M34](/packages/phpcollection-phpcollection)

PHPackages © 2026

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