PHPackages                             mfn/util-simpleorderedmap - 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. mfn/util-simpleorderedmap

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

mfn/util-simpleorderedmap
=========================

Ordered map accepting arbitrary keys

v0.0.2(11y ago)02422MITPHPPHP &gt;=5.4.0

Since Aug 30Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mfn/php-util-simpleorderedmap)[ Packagist](https://packagist.org/packages/mfn/util-simpleorderedmap)[ Docs](http://github.com/mfn/php-util-simpleorderedmap)[ RSS](/packages/mfn-util-simpleorderedmap/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (3)Used By (2)

Ordered map accepting arbitrary keys for PHP[ ![Travis Build Status](https://camo.githubusercontent.com/c73810be34c3d9c063192c68950c3b182050f3860da0bafae587bfbfe5b2556e/68747470733a2f2f7472617669732d63692e6f72672f6d666e2f7068702d7574696c2d73696d706c656f7264657265646d61702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mfn/php-util-simpleorderedmap)
==========================================================================================================================================================================================================================================================================================================================================================================

[](#ordered-map-accepting-arbitrary-keys-for-php-)

Homepage:

Basic usage:
------------

[](#basic-usage)

```
$map = new \Mfn\Util\Map\SimpleOrderedMap;
$map->add(new \stdClass, "value");
foreach ($map->keys() as $key) {
  echo $map->get($key), PHP_EOL;
}
```

Outputs: `value`

Common usage
------------

[](#common-usage)

Add and set keys/values:

```
use \Mfn\Util\Map\SimpleOrderedMap;
$map = SimpleOrderedMap;
$map->add($key, $val); # throws exception if key already exists
$map->set($key, $val); # replaces value if key already exists
```

Retrieve:

```
$val = $map->get($key); # throws exception if key does not exist
if ($map->exists($key)) {
  # ...
}
```

Remove:

```
$map->del($key); # throws exception if key does not exist
```

The keys are always kept in their order when removing, this position index are available:

```
$index = $map->getKeyPosition($key);
$key = $map->getKayAt($index);
$val = $map->getValueAt($index);
```

Create from existing hashes or arrays:

```
use \Mfn\Util\Map\SimpleOrderedMap;
$map = SimpleOrderedMap::fromHash(['a'=>true,10=>NULL]);
$map->keys(); # ['a',10]
$map->values(): # [true,NULL]

# The same with separate arrays. Note: arrays length must match
$map = SimpleOrderedMap::fromArrays(
  ['a',10],
  [true,NULL]
);
$map->keys(); # ['a',10]
$map->values(): # [true,NULL]
```

Many more methods, please see [the source of SimpleOrderedMap](lib/SimpleOrderedMap.php)

Using with key/value validation
-------------------------------

[](#using-with-keyvalue-validation)

If you feel like you need some kind of validation, you can use SimpleOrderedValidatingMap which provides callbacks for checking new added key and values:

```
use Mfn\Util\Map\SimpleOrderedValidatingMap as Map;

$map = new Map(
              function($key) {
                if ($key instanceof \stdClass) {
                  return;
                }
                throw new \Mfn\Util\Map\SimpleOrderedValidatingMapException(
                  'Only keys of type stdClass are allowed'
                );
              },
              function($value) {
                if ($value instanceof \stdClass) {
                  return;
                }
                throw new \Mfn\Util\Map\SimpleOrderedValidatingMapException(
                  'Only values of type stdClass are allowed'
                );
              }
           );
# Throws an exception
$map->add(1,2);
```

Install
=======

[](#install)

Using composer: `composer.phar require mfn/util-simpleorderedmap 0.0.2`

Contribute
==========

[](#contribute)

Fork it, hack on a feature branch, create a pull request

© Markus Fischer

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

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

Total

2

Last Release

4251d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

utilitymap

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mfn-util-simpleorderedmap/health.svg)

```
[![Health](https://phpackages.com/badges/mfn-util-simpleorderedmap/health.svg)](https://phpackages.com/packages/mfn-util-simpleorderedmap)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[phpcollection/phpcollection

General-Purpose Collection Library for PHP

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

PHP 7.1 enum implementation

379146.0M11](/packages/dasprid-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49444.8M97](/packages/marc-mabe-php-enum)[spatie/geocoder

Geocoding addresses to coordinates

8404.8M15](/packages/spatie-geocoder)

PHPackages © 2026

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