PHPackages                             ecfectus/dotable - 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. ecfectus/dotable

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

ecfectus/dotable
================

A simple dot notation accessible array class and trait.

138PHP

Since Oct 8Pushed 9y ago2 watchersCompare

[ Source](https://github.com/ecfectus/dotable)[ Packagist](https://packagist.org/packages/ecfectus/dotable)[ RSS](/packages/ecfectus-dotable/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Dotable
=======

[](#dotable)

[![Build Status](https://camo.githubusercontent.com/251628ddbfed68c0601d9eebad4e23d5e15aa30475b7d12e6ce4ed245089d070/68747470733a2f2f7472617669732d63692e6f72672f65636665637475732f646f7461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ecfectus/dotable)

A simple dot notation accessible array class and trait, implementing DotableInterface, ArrayAccess, IteratorAggregate, Countable, JsonSerializable.

This class can turn normal arrays into super arrays with dot notation, you can use the helper methods `set`, `get`, `has`, `forget`, `prepend`, `append`, `merge`, and `count` to modify the underlying array. Or You can access it just like any other array using `foreach`, `isset`, ``unset`, `count`, and `$array\['dot.notation.key'\]`.

Usage
-----

[](#usage)

```
$d = new Dotable([]);

//these are both the same.
$d['one'] = ['two' => ['three' => 1], 'four' => ['val']];
===
$d->set('one', ['two' => ['three' => 1], 'four' => ['val']);

//and these
$var = $d['one.two.three'];
===
$var = $d->get('one.two.three', 1);//optional default value

//and these
$d['one.two.three'] = 2;
===
$d->set('one.two.three', 2);

//existence is the same
isset($d['one.two.three']);//true
isset($d['one.two.five']);//false
===
$d->has('one.two.three');//true
$d->has('one.two.five');//false

//and removal
unset($d['one.two.three']);
===
$d->forget('one.two.three');

//prepend
$v = $d['one.four'];
array_unshift($v, 'val2');
$d['one.four'] = $v
===
$d->prepend('one.four', 'val2');

//append
$v = $d['one.four'];
$v[] = 'val2';
$d['one.four'] = $v
===
$d->append('one.four', 'val2');

//merge
// merging is a little different, array_merge_recursive has some weird side effects for multi dimensional arrays with different value types,
// by default we use the dotable merge stratergy which overcomes this with distinct values,
// but if your expecting exactly what array_merge_recursive does, simply pass false as the third argument.

$res = array_merge_recursive($d['one'], ['two' => ['three' => 2]);
===
$d->merge('one', ['two' => ['three' => 2], true|false);

//count
count($d);
===
$d->count();

//get a plain array
$d->toArray();

//loop over the array
foreach($d as $key => $value){}
===
foreach($d->toArray() as $key => $value){}
```

Using the trait
---------------

[](#using-the-trait)

The dotable class simply uses the trait provided and implements all the interfaces: DotableInterface, ArrayAccess, IteratorAggregate, Countable, JsonSerializable.

The full functionality can be used in a different class not extended from the Dotable class.

```
class MyClass extends Dotable implements DotableInterface, ArrayAccess, IteratorAggregate, Countable, JsonSerializable
{}

//or

class MyClass implements DotableInterface, ArrayAccess, IteratorAggregate, Countable, JsonSerializable
{
    use DotableTrait;

    public function __construct(array $items = [])
    {
        $this->set('', $items);//set the items using the traits method on the root index.
    }
}
```

Now `MyClass` has all the features of dotable without having to extends it. Bear in mind if you provide the same methods in your class that overwrite the trait methods (including the implemented interface methods) you will loose functionality. To ensure its maintained you will need to rewrite the method signatures when using the trait as explained in the php docs:  #example 6.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b8fdb3cf22dac46100ad95eddb94f98b2a7a5002b29c4d2f812113f2867ff35?d=identicon)[leemason](/maintainers/leemason)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/ecfectus-dotable/health.svg)

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

###  Alternatives

[cjmellor/level-up

This package allows users to gain experience points (XP) and progress through levels by performing actions on your site. It can provide a simple way to track user progress and implement gamification elements into your application

670109.6k](/packages/cjmellor-level-up)

PHPackages © 2026

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