PHPackages                             gaming-engine/dictionary - 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. gaming-engine/dictionary

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

gaming-engine/dictionary
========================

Dictionary implementation for PHP

1.0.1(4y ago)19.1k↓25%MITPHPPHP ^8.0|^8.1

Since Jul 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/gaming-engine/dictionary)[ Packagist](https://packagist.org/packages/gaming-engine/dictionary)[ Docs](https://github.com/gaming-engine/dictionary)[ RSS](/packages/gaming-engine-dictionary/feed)WikiDiscussions main Synced 1mo ago

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

PHP Dictionary
==============

[](#php-dictionary)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ae83c82ed8819de5384850c4a815c29a179e79e349e74a45ccef8fe909d224d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67616d696e672d656e67696e652f64696374696f6e6172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gaming-engine/dictionary)[![Total Downloads](https://camo.githubusercontent.com/c9e1ddcd997103e7c65a603ec0390fb58f3c424860a6ea088f6e210343076d36/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67616d696e672d656e67696e652f64696374696f6e6172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gaming-engine/dictionary)[![GitHub Actions](https://github.com/gaming-engine/dictionary/actions/workflows/main.yml/badge.svg)](https://github.com/gaming-engine/dictionary/actions/workflows/main.yml/badge.svg)

A quick and easy dictionary implementation for PHP.

This package was initially ported (and upgraded) from [here](https://github.com/dpolac/dictionary).

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

[](#installation)

You can install the package via composer:

```
composer require gaming-engine/dictionary
```

Usage
-----

[](#usage)

```
$dict = new \GamingEngine\Dictionary\Dictionary();

$dict[new \stdClass()] = 12;
$dict['php'] = 23;
$dict[100] = 'dictionary';
```

Class `\GamingEngine\Dictionary\Dictionary` implements `Iterator`, `ArrayAccess`, `Countable` and `Serializable`. It also provides methods for creating and sorting Dictionary and for converting it to array.

Valid types of keys for the Dictionary are:

- object
- integer
- float
- string
- bool
- null

You cannot use:

- Closure
- array

### Creating

[](#creating)

To create empty Dictionary, use constructor.

```
$dict = new \GamingEngine\Dictionary\Dictionary();
```

You can also create Dictionary from key-value pairs.

```
$dict = \GamingEngine\Dictionary\Dictionary::fromPairs([
    ['key1', 'value1'],
    ['key2', 'value2'],
    ['key3', 'value3'],
]);
```

Last option is to create Dictionary from array.

```
$dict = \GamingEngine\Dictionary\Dictionary::fromArray([
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3',
]);
```

### Converting to PHP array

[](#converting-to-php-array)

There are three methods that let you retrieve data as array:

- `Dictionary::keys()` - returns array of keys,
- `Dictionary::values()` - returns array of values,
- `Dictionary::toPairs()` - returns array of key-value pairs; each pair is 2-element array.

### Copying Dictionary

[](#copying-dictionary)

Unlike an array, Dictionary is an object and that means it is reference type. If you want the copy of Dictionary, you have to use clone keyword or call Dictionary::getCopy() method.

### Sorting elements

[](#sorting-elements)

Just like an array, Dictionary is ordered. To sort Dictionary, use Dictionary::sortBy($callback, $direction) method. Any argument can be omitted.

- `$callback` will be called for every element. Dictionary will be ordered by values returned by callback. First argument of the callback is value and second is key of element. Instead of callable, you can use "values" or "keys" string.
- `$direction` can be "asc" or "desc". Default value is "asc".

Examples of sorting:

```
$dictionary->sortBy('values','asc');
```

```
$dictionary->sortBy(function($value, $key) {
    return $value->title . $key->name;
}, 'desc');
```

`sortBy` changes Dictionary it is called for. If you want sorted copy, chain it with `getCopy`.

```
$sortedDictionary = $dictionary->getCopy()->sortBy('values', 'asc');
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andrew Judd](https://github.com/gaming-engine)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

2

Last Release

1684d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c1a37465afdee14b2740a387deaae40ac376e38015db7af98f90b7fd97fed22?d=identicon)[awjudd](/maintainers/awjudd)

---

Top Contributors

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

---

Tags

dictionaryphpdictionarygaming-engine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gaming-engine-dictionary/health.svg)

```
[![Health](https://phpackages.com/badges/gaming-engine-dictionary/health.svg)](https://phpackages.com/packages/gaming-engine-dictionary)
```

###  Alternatives

[knplabs/dictionary-bundle

Are you often tired to repeat static choices like gender or civility in your apps ?

88284.0k](/packages/knplabs-dictionary-bundle)[equip/structure

Simple, immutable data structures

40201.9k2](/packages/equip-structure)[sinergi/dictionary

PHP Dictionary library

1514.1k2](/packages/sinergi-dictionary)[webinarium/php-dictionary

Static dictionary implementation for PHP

1019.1k](/packages/webinarium-php-dictionary)

PHPackages © 2026

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