PHPackages                             oliverde8/associative-array-simplified - 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. oliverde8/associative-array-simplified

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

oliverde8/associative-array-simplified
======================================

Allow simplified manupulation of recursive associative arrays.

1.0.0(9y ago)113.1k—7.1%[1 issues](https://github.com/oliverde8/AssociativeArraySimplified/issues)3MITPHPPHP &gt;=5.5.0CI failing

Since Feb 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/oliverde8/AssociativeArraySimplified)[ Packagist](https://packagist.org/packages/oliverde8/associative-array-simplified)[ RSS](/packages/oliverde8-associative-array-simplified/feed)WikiDiscussions master Synced yesterday

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

PHP - Associative Arrays Simplified
===================================

[](#php---associative-arrays-simplified)

This library allow simplified manipulation of recursive associative arrays with an object oriented aproach in php.

[![Latest Stable Version](https://camo.githubusercontent.com/792bdc1d596c778868cc281c4f1a0046ca69f5c1d510d55d00af8b955a2ad8de/68747470733a2f2f706f7365722e707567782e6f72672f6f6c697665726465382f6173736f636961746976652d61727261792d73696d706c69666965642f762f737461626c65)](https://packagist.org/packages/oliverde8/associative-array-simplified)[![Build Status](https://camo.githubusercontent.com/f371f01a94d59b6638c41f60401be139301767eca2de02a4cb6113e8dbd80083/68747470733a2f2f7472617669732d63692e6f72672f6f6c697665726465382f4173736f63696174697665417272617953696d706c69666965642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/oliverde8/AssociativeArraySimplified)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a62465f25d448fd09d869025f2e67bed893eaba8365ad6c711eaca5d671e149c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6c697665726465382f4173736f63696174697665417272617953696d706c69666965642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/oliverde8/AssociativeArraySimplified/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/8f8c281d771e1ff739fcb5a2446385f17cf6f3a3ccc61b9041c2b03aaac56319/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f6c697665726465382f4173736f63696174697665417272617953696d706c69666965642f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/oliverde8/AssociativeArraySimplified/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/4b13dd845a43558a45e72e3951828bd7eadaee6238d6fb6e76ffd972eea24252/68747470733a2f2f706f7365722e707567782e6f72672f6f6c697665726465382f6173736f636961746976652d61727261792d73696d706c69666965642f646f776e6c6f616473)](https://packagist.org/packages/oliverde8/associative-array-simplified)[![License](https://camo.githubusercontent.com/b3b4d52a97f7075089a3954cc2900252168ee888d1523980222644673e3a65f1/68747470733a2f2f706f7365722e707567782e6f72672f6f6c697665726465382f6173736f636961746976652d61727261792d73696d706c69666965642f6c6963656e7365)](https://packagist.org/packages/oliverde8/associative-array-simplified)

[![SensioLabsInsight](https://camo.githubusercontent.com/b704d0b56ab6657b899fd5d127101e39e00e6ecc3c193db107198177c43c76c6/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66633463363936382d356332372d343965652d396364612d3464363438616136353066392f6269672e706e67)](https://insight.sensiolabs.com/projects/fc4c6968-5c27-49ee-9cda-4d648aa650f9)

Associative Array
-----------------

[](#associative-array)

This is the main clas of the library. It allows the manipulation of the association arrays with ease.

This allow you to get data from an associative array with ease. This can be used many places even for getting information from SESSION or POST &amp; GET values.

Typically when we try and get information from a an array of which we don't know the content we need to write a lot of conditions :

```
$array = ['a' => ['b' => 2, 'c' => 3]];
if (isset($array['a'])) {
    $valB = isset($array['a']['b']) ? $array['a']['b'] : "default";
    $valB = isset($array['a']['c']) ? $array['a']['c'] : "default";
}
```

After a certain while we write a lot conditions and the array is very nested it becomes difficult to understand. This library makes it much easier to write code of this type &amp; makes it easier to read and understand. The code above is simply replaced by :

```
$object = new AssociativeArray( ['a' => ['b' => 2, 'c' => 3]]);
$valB = $object->get('a/b', 'default');
$valB = $object->get('a/c', 'default');
```

Requirments
-----------

[](#requirments)

- `PHP` 5.4 or higher.

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

[](#installation)

You should always install the library using composer.

```
composer require oliverde8/associative-array-simplified
```

**Manual installation is not recomended and not supported.**

Usage Exemples
--------------

[](#usage-exemples)

### Get values from a simple array

[](#get-values-from-a-simple-array)

```
$array = ['a' => 1, 'b' => 2,];
$object = new AssociativeArray($array);

$object->get('a');
//This will return '1'

$object->get('c');
//This will return null
```

### Get a value and if no value is set get a default one

[](#get-a-value-and-if-no-value-is-set-get-a-default-one)

```
$object->get('c', 10);
//This will return 10
```

### Get nested values recursively

[](#get-nested-values-recursively)

```
$array = ['a' => ['b' => 2]];
$object = new AssociativeArray($array);

$object->get('a');
//This will return ['b' => 2]

$object->get(['a', 'b']);
//This will return 2
```

> And of course you can continue to use default values with the recursive get.

### Use separators in the string keys to get nested values

[](#use-separators-in-the-string-keys-to-get-nested-values)

The default separator is `/`

```
$object->get('a/b');
//This will return 2
```

### You can set new values or replace them.

[](#you-can-set-new-values-or-replace-them)

```
// Both of these do the same thing.
$object->set('a/d', 10);
$object->set(['a','d'], 10);
```

### You can get back your array

[](#you-can-get-back-your-array)

```
// And you get back the array.
$object->array()
```

### Using custom separators

[](#using-custom-separators)

When creating the AssociativeArray you can specify the separator to use. So instead of

```
$array = ['a' => ['b' => 2]];
$object = new AssociativeArray($array);
$this->get('a/b');
```

You can write

```
$array = ['a' => ['b' => 2]];
$object = new AssociativeArray($array, '.');
$this->get('a.b');
```

### Example usage of static methods

[](#example-usage-of-static-methods)

The class has also static methods to manipulate your array directly. The method of the objects actually uses these static methods to manipulate the array.

```
$array = ['a' => ['b' => 2]];
AssociativeArray::getFromKey($array, 'a/b');
// Will return 2
```

And to set new data.

```
$array = ['a' => ['b' => 2]];
AssociativeArray::setFromKey($array, 'a/c', 'yop);
// Will return ['a' => ['b' => 2, 'c' => 'yop']]
```

Other functions
---------------

[](#other-functions)

The class has also other functions.

- **clear :** Empties all the data from the array.
- **keyExist :** Checks if a key exists. (value may be null)

FAQ
---

[](#faq)

### Why don't the associative array has an iterator ?

[](#why-dont-the-associative-array-has-an-iterator-)

Associative Array Simplified doesen't try and replace arrays; other libraries were designed to do so. This library simply makes it easier yo access values in associative arrays.

### Why don't the associative array return associative array instead of normal array's ?

[](#why-dont-the-associative-array-return-associative-array-instead-of-normal-arrays-)

This is something I spent quite some time to decide, but doing it that way would require during the creation of the associative array to process the array to create the nested associative arrays. This would have slowned then the process of creation without really increasing perormance at any other level. On long term I might create a second object working that way.

There is some questions about this how should this work :

```
$array = ['a' => ['b' => 2]];
$object = new AssociativeArray($array);

$object->get('a');
//This will return ['b' => 2]

$object->get(a)->get('b');
//Should return 2

$object->get(a)->get('b')->get('c', 'default');
//Will make an error but should have returned 'default'
```

So there is some reflexion to be done on the subject.

### Why don't the assotiative array use references ?

[](#why-dont-the-assotiative-array-use-references-)

It's planned. Current implementation is slower as it duplicated the arrays during the set operations.

### ...

[](#)

TODO
----

[](#todo)

- Add some more options (clear, disable new data ...)
- uses references to use less memory.
- create second version returning Associative Array instead of normal arrays.
- Something else? Open a ticket :)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

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

3423d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3658513?v=4)[De Cramer Oliver](/maintainers/oliverde8)[@oliverde8](https://github.com/oliverde8)

---

Top Contributors

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

---

Tags

phpphp-library

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/oliverde8-associative-array-simplified/health.svg)

```
[![Health](https://phpackages.com/badges/oliverde8-associative-array-simplified/health.svg)](https://phpackages.com/packages/oliverde8-associative-array-simplified)
```

###  Alternatives

[webchemistry/forms-wizard

Wizard component for nette/forms

159.2k](/packages/webchemistry-forms-wizard)

PHPackages © 2026

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