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

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

vkr/collection
==============

Store and retrieve objects based on keys

v1.0.2(7y ago)036.1k1MITPHPPHP &gt;=7.2

Since Sep 20Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (4)Used By (0)

Overview
========

[](#overview)

This package implements a collection of objects of same type that have a unique field defined as a key. It requires PHP 7.2+ to run.

Usage
=====

[](#usage)

First, create a data class that implements `VKR\Collection\Contracts\Collectable` and define its `getKey()` method. It is important that `getKey()` should return the value of the key field, not its name, so it should look like this:

```
public function getKey(): string
{
    return $this->keyField;
}

```

It is up to client coders to ensure that the value of the key field is always string and always unique.

Then, initialize `VKR\Collection\Collection` and add your data objects to it using `add(Collectable $object)`. All elements of a single collection object MUST be of same type. If an object with the same key exists in the collection, `add()` will overwrite it.

`remove(string $key)` will delete an object from the collection by key and return the removed object. If no element with the given key is found, it will return `null`.

`get(string $key)` will retrieve objects by key, or `null` if not found.

`all()` retrieves zero-indexed array of collection member objects. If an object was removed from the collection, keys get re-indexed to the natural order of elements.

`toScalarArray(string $valueField)` converts the collection into one-dimensional associative array with values of the key field as keys and values of `$valueField` as values.

`toArray()` converts the collection into an associative array that is identical to the result of `all()`, but numeric keys are swapped for values of the key field.

If the data class implements `VKR\Collection\Contracts\Arrayable`, `toArray()` will attempt deep rendering by calling the `toArray()` method on each data object.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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

Total

3

Last Release

2798d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79f5fa971e7fda7a6180c1bdfca4f819a43b7681ec4e04c66b184a082fb5a20f?d=identicon)[wladislavk](/maintainers/wladislavk)

---

Top Contributors

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

---

Tags

phpcollection

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/vkr-collection/health.svg)](https://phpackages.com/packages/vkr-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)
