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

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

stk2k/collection
================

Simple PHP collection class library

0.1.3(4y ago)14.6k4MITPHPPHP &gt;=7.2

Since Nov 19Pushed 4y ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (5)Used By (4)

Simple PHP collection class library
===================================

[](#simple-php-collection-class-library)

[![Latest Version on Packagist](https://camo.githubusercontent.com/13a0c8a296d0f76c744fe9fc55ed079a4ae536d4f00c9b4dc0c8161e6179ab59/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746b326b2f636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stk2k/collection)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a312951d46e0816dbabb1c0895445ee4fd7de03e14fb5a62be4cf810d052a34f/68747470733a2f2f7472617669732d63692e6f72672f73746b326b2f636f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/stk2k/collection)[![Coverage Status](https://camo.githubusercontent.com/8bd00cb74e662851de450ae63048863a08c5497f0cf78a31b5ecaa34587c50a2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73746b326b2f636f6c6c656374696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/stk2k/collection?branch=master)[![Code Climate](https://camo.githubusercontent.com/2d924c9ef9d62c95ad6b708c67787b2d58e6f0f335c00efc1d2ac3e46f3d8066/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73746b326b2f636f6c6c656374696f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/stk2k/collection)[![Total Downloads](https://camo.githubusercontent.com/83a076de43b6359d06d0223e1599cbef1982b3180b1d0a6ac1b5270dfed5d570/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746b326b2f636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stk2k/collection)

Description
-----------

[](#description)

Simple PHP collection class library

Feature
-------

[](#feature)

- Sortable(ArrayList/Queue/Stack/Vector)

Supported Data Structure
------------------------

[](#supported-data-structure)

- ArrayList
- Collection
- Property(supports hierarchical access to array for string/int/float/bool values)
- Queue
- Set
- Stack
- Vector

Demo
----

[](#demo)

### Collection

[](#collection)

```
$data = ['red', 'green', 'blue'];

echo 'iterate:' . PHP_EOL;
$output = [];
foreach(new Collection($data) as $item){
    $output[] = $item;
}
echo ' ' . implode(',', $output) . PHP_EOL;     // red,green,blue

echo 'join:' . PHP_EOL;
echo ' ' . (new Collection($data))->join() . PHP_EOL;    // red,green,blue

echo 'replace:' . PHP_EOL;
echo ' ' . (new Collection($data))->replace('green', 'yellow')->join() . PHP_EOL;     // red,yellow,blue

echo 'each:' . PHP_EOL;
(new Collection($data))->each(function($item){
    echo "[$item],";
});    // [red],[green],[blue],

echo 'map:' . PHP_EOL;
echo ' ' . (new Collection($data))->map(function($item){
    return "[$item]";
})->join() . PHP_EOL;      // [red],[green],[blue]

echo 'reduce:' . PHP_EOL;
echo ' ' . (new Collection($data))->reduce(function($tmp,$item){
    return $tmp + strlen($item);
}) . PHP_EOL;     // 12
```

### ArrayList

[](#arraylist)

```
$data = ['red', 'green', 'blue'];

echo 'iterate:' . PHP_EOL;
$output = [];
foreach(new ArrayList($data) as $item){
    $output[] = $item;
}
echo ' ' . implode(',', $output) . PHP_EOL;     // red,green,blue

echo 'join:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->join() . PHP_EOL;    // red,green,blue

echo 'first:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->first() . PHP_EOL;    // red

echo 'last:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->last() . PHP_EOL;    // blue

echo 'reverse:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->reverse()->join() . PHP_EOL;      // blue,green,red

echo 'replace then reverse:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->replace('green', 'yellow')->reverse()->join() . PHP_EOL;      // blue,yellow,red

echo 'shift:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->shift($item)->join() . PHP_EOL;       // green,blue

echo 'unshift:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->unshift('yellow')->join() . PHP_EOL;       // yellow,red,green,blue

echo 'push:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->push('yellow')->join() . PHP_EOL;       // red,green,blue,yellow

echo 'pop:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->pop($item)->join() . PHP_EOL;       // red,green

echo 'sort:' . PHP_EOL;
echo ' ' . (new ArrayList($data))->sort()->join() . PHP_EOL;       // blue,green,red
```

### Vector

[](#vector)

```
$data = ['red', 'green', 'blue'];

echo 'iterate:' . PHP_EOL;
$output = [];
foreach(new Vector($data) as $item){
    $output[] = $item;
}
echo ' ' . implode(',', $output) . PHP_EOL;     // red,green,blue

echo 'join:' . PHP_EOL;
echo ' ' . (new Vector($data))->join() . PHP_EOL;    // red,green,blue

echo 'first:' . PHP_EOL;
echo ' ' . (new Vector($data))->first() . PHP_EOL;    // red

echo 'last:' . PHP_EOL;
echo ' ' . (new Vector($data))->last() . PHP_EOL;    // blue

echo 'reverse:' . PHP_EOL;
echo ' ' . (new Vector($data))->reverse()->join() . PHP_EOL;      // blue,green,red

echo 'replace then reverse:' . PHP_EOL;
echo ' ' . (new Vector($data))->replace('green', 'yellow')->reverse()->join() . PHP_EOL;      // blue,yellow,red

echo 'shift:' . PHP_EOL;
echo ' ' . (new Vector($data))->shift($item)->join() . PHP_EOL;       // green,blue

echo 'unshift:' . PHP_EOL;
echo ' ' . (new Vector($data))->unshift('yellow')->join() . PHP_EOL;       // yellow,red,green,blue

echo 'push:' . PHP_EOL;
echo ' ' . (new Vector($data))->push('yellow')->join() . PHP_EOL;       // red,green,blue,yellow

echo 'pop:' . PHP_EOL;
echo ' ' . (new Vector($data))->pop($item)->join() . PHP_EOL;       // red,green

echo 'sort:' . PHP_EOL;
echo ' ' . (new Vector($data))->sort()->join() . PHP_EOL;       // blue,green,red
```

### Stack

[](#stack)

```
$data = ['red', 'green', 'blue'];

echo 'iterate:' . PHP_EOL;
$output = [];
foreach(new Stack($data) as $item){
    $output[] = $item;
}
echo ' ' . implode(',', $output) . PHP_EOL;     // red,green,blue

echo 'join:' . PHP_EOL;
echo ' ' . (new Stack($data))->join() . PHP_EOL;    // red,green,blue

echo 'peek:' . PHP_EOL;
echo ' ' . (new Stack($data))->peek() . PHP_EOL;    // red

echo 'reverse:' . PHP_EOL;
echo ' ' . (new Stack($data))->reverse()->join() . PHP_EOL;      // blue,green,red

echo 'replace then reverse:' . PHP_EOL;
echo ' ' . (new Stack($data))->replace('green', 'yellow')->reverse()->join() . PHP_EOL;      // blue,yellow,red

echo 'push:' . PHP_EOL;
echo ' ' . (new Stack($data))->push('yellow')->join() . PHP_EOL;       // red,green,blue,yellow

echo 'pop:' . PHP_EOL;
echo ' ' . (new Stack($data))->pop($item)->join() . PHP_EOL;       // red,green

echo 'sort:' . PHP_EOL;
echo ' ' . (new Stack($data))->sort()->join() . PHP_EOL;       // blue,green,red
```

### HashMap

[](#hashmap)

```
$data = ['name' => 'David', 'age' => 21, 'height' => 172.2];

echo 'iterate:' . PHP_EOL;
$output = [];
foreach(new HashMap($data) as $item){
    $output[] = $item;
}
echo ' ' . implode(',', $output) . PHP_EOL;     // David,21,172.2

echo 'join:' . PHP_EOL;
echo ' ' . (new HashMap($data))->join() . PHP_EOL;    // David,21,172.2
```

### Set

[](#set)

```
$data = ['red', 'green', 'blue'];

echo 'iterate:' . PHP_EOL;
$output = [];
foreach(new Set($data) as $item){
    $output[] = $item;
}
echo ' ' . implode(',', $output) . PHP_EOL;     // red,green,blue

echo 'join:' . PHP_EOL;
echo ' ' . (new Set($data))->join() . PHP_EOL;    // red,green,blue
```

Requirement
-----------

[](#requirement)

PHP 7.2 or later

Installing stk2k/collection
---------------------------

[](#installing-stk2kcollection)

The recommended way to install stk2k/collection is through [Composer](http://getcomposer.org).

```
composer require stk2k/collection
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

License
-------

[](#license)

This library is licensed under the MIT license.

Author
------

[](#author)

[stk2k](https://github.com/stk2k)

Disclaimer
----------

[](#disclaimer)

This software is no warranty.

We are not responsible for any results caused by the use of this software.

Please use the responsibility of the your self.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity45

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

Total

4

Last Release

1800d ago

PHP version history (2 changes)0.1.0PHP &gt;=7.1

0.1.2PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/955f3d564811dc5e1212c1a7a66bc4eb7e11ac166cc38600f244dc25f97d3ef4?d=identicon)[stk2k](/maintainers/stk2k)

---

Top Contributors

[![stk2k](https://avatars.githubusercontent.com/u/985640?v=4)](https://github.com/stk2k "stk2k (7 commits)")

---

Tags

phpcollection

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[werxe/laravel-collection-macros

Custom Laravel Collection macros.

2625.8k](/packages/werxe-laravel-collection-macros)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[jshannon63/jsoncollect

Supercharge your JSON using collections

154.9k1](/packages/jshannon63-jsoncollect)

PHPackages © 2026

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