PHPackages                             carlosv2/map - 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. carlosv2/map

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

carlosv2/map
============

Enhance PHP arrays to allow any offset type

1.0.0(9y ago)039MITPHPPHP &gt;=5.3,&lt;7.1

Since May 26Pushed 9y ago1 watchersCompare

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

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

Map
===

[](#map)

Map allows you to use an array-like object which allows keys to be of any type as opposed to the default integer or string types.

[![License](https://camo.githubusercontent.com/7bb3b52a7f1a01dc4e4096a7aadb4338b0b81168a3565aafd773def8e7fd839e/68747470733a2f2f706f7365722e707567782e6f72672f6361726c6f7376322f6d61702f6c6963656e7365)](https://packagist.org/packages/carlosv2/map)[![Build Status](https://camo.githubusercontent.com/48510f0c456793bfd1e2ed5d15928fadd636ecedc4e33264d3768d40e1e96269/68747470733a2f2f7472617669732d63692e6f72672f6361726c6f7356322f4d61702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/carlosV2/Map)[![SensioLabsInsight](https://camo.githubusercontent.com/bcebbad4e1eb64fa1a1668d2d3073921625f36b11a527bc7fd87d5d1b2b9940f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33323233656631392d623337382d343462622d616236312d3435333864653834363664362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/3223ef19-b378-44bb-ab61-4538de8466d6)

### Installation

[](#installation)

Install with:

```
$ composer require carlosv2/map

```

### Usage

[](#usage)

To use Map you only need to create an instance of it and start using it as if it was an regular array:

```
$foo = new Foo();

$map = new Map();
$map[$foo] = 'bar';

```

You can use any type you want as key. If you want, you can even mix them:

```
$map = new Map();

$map[null] = 'null';
$map[[]] = 'array';
$map['string'] = 'string';
$map[1] = 'integer';
$map[true] = 'boolean';
$map[new \stdClass()] = 'object';

foreach ($map as $key => $value) {
    var_dump($key, $value);
}

```

### API

[](#api)

The following functions are available in the Map class.

has:
----

[](#has)

Checks whether a key exists or not:

```
$obj = new \stdClass();

$map = new Map();
$map[$obj] = 'value';

$map->has($obj); // true
$map->has([]); // false

```

get:
----

[](#get)

Returns the value associated with the given key:

```
$obj = new \stdClass();

$map = new Map();
$map[$obj] = 'value';

$map->get($obj); // 'value'
$map->get([]); // null

```

Optionally, a fallback value can be returned if the given key does not exist:

```
$map = new Map();
$map->get([], 'default'); // 'default'

```

set:
----

[](#set)

Assigns the given value to the given key:

```
$map = new Map();

$map->set($key, $value); // Equivalent to: $map[$key] = $value;

```

keys:
-----

[](#keys)

Returns the array of keys for that instance:

```
$map = new Map();

$map[null] = 'null';
$map[[]] = 'array';
$map[true] = 'boolean';

$map->keys(); // [null, [], true]

```

values:
-------

[](#values)

Returns the array of values for that instance:

```
$map = new Map();

$map[null] = 'null';
$map[[]] = 'array';
$map[true] = 'boolean';

$map->values(); // ['null', 'array', 'boolean']

```

map:
----

[](#map-1)

Similar to `array_map` but it returns another Map instance instead. The callable function may have the key as a second argument:

```
$map = new Map();

$map[null] = 'null';
$map[[]] = 'array';
$map[true] = 'boolean';

$newMap = $map->map(function ($value, $key) { return json_encode($key) . '_' . $value; });
$newMap->keys(); // [null, [], true]
$newMap->values(); // ['null_null', '[]_array', 'true_boolean']

```

### Interfaces

[](#interfaces)

The Map class implements the following interfaces:

- [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php)
- [Countable](http://php.net/manual/en/class.countable.php)
- [IteratorAggregate](http://php.net/manual/en/class.iteratoraggregate.php)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3635d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7bd7a8f2b6884a04c3282dea24b9e0f10e0ff33e085bcc0e48797c4afc7d8758?d=identicon)[carlosV2](/maintainers/carlosV2)

---

Top Contributors

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

---

Tags

arraymaptypesoffsetAssociative

### Embed Badge

![Health badge](/badges/carlosv2-map/health.svg)

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

###  Alternatives

[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.2k412.9k11](/packages/aimeos-map)[minwork/array

Pack of advanced array functions specifically tailored for: associative (assoc) array, multidimensional array, array of objects and handling nested array elements

66256.1k5](/packages/minwork-array)[graze/data-structure

Data collections and containers

12287.4k8](/packages/graze-data-structure)

PHPackages © 2026

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