PHPackages                             adbario/php-dot-notation - 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. adbario/php-dot-notation

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

adbario/php-dot-notation
========================

PHP dot notation access to arrays

3.3.0(3y ago)4638.8M—0.4%4920MITPHPPHP ^7.4 || ^8.0CI passing

Since Sep 14Pushed 3mo ago16 watchersCompare

[ Source](https://github.com/adbario/php-dot-notation)[ Packagist](https://packagist.org/packages/adbario/php-dot-notation)[ Docs](https://github.com/adbario/php-dot-notation)[ RSS](/packages/adbario-php-dot-notation/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (22)Used By (20)

[![PHP Dot Notation](https://user-images.githubusercontent.com/22136575/161442912-96d96b7b-9c99-4854-959c-86636093cea4.png)](https://user-images.githubusercontent.com/22136575/161442912-96d96b7b-9c99-4854-959c-86636093cea4.png)

 [![Tests Status](https://camo.githubusercontent.com/f40ac97a4256578327dac7947858c88fdbf88fc3f2bbc261e38f74faafd01bfd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6164626172696f2f7068702d646f742d6e6f746174696f6e2f74657374732e796d6c3f6272616e63683d332e78266c6162656c3d5465737473267374796c653d666f722d7468652d6261646765)](https://github.com/adbario/php-dot-notation/actions/workflows/tests.yml?query=branch%3A3.x) [![Coverage Status](https://camo.githubusercontent.com/b56726208f8a5efe726c57618a350d2c4219c67431d1d2b848c6ac65ce3ee372/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f6164626172696f2f7068702d646f742d6e6f746174696f6e2f332e783f7374796c653d666f722d7468652d6261646765)](https://coveralls.io/github/adbario/php-dot-notation?branch=3.x) [![Total Downloads](https://camo.githubusercontent.com/0f3fc91c52a6f3289140fcbf1538dcb36af3c805f921e51ea82d84a52e39dd7b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6164626172696f2f7068702d646f742d6e6f746174696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/adbario/php-dot-notation) [![Latest Stable Version](https://camo.githubusercontent.com/f303b0fc75d2c5297580e36f573da8b6944bb5107f21887c0f758a81d5276d19/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6164626172696f2f7068702d646f742d6e6f746174696f6e3f6c6162656c3d737461626c65267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/adbario/php-dot-notation) [![License](https://camo.githubusercontent.com/235f2d3c1656e3b90a8176ac7f710feb39dd13612a51caf52ef823ef770bb69a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6164626172696f2f7068702d646f742d6e6f746174696f6e3f7374796c653d666f722d7468652d6261646765)](LICENSE.md)

About Dot
---------

[](#about-dot)

Dot provides an easy access to arrays of data with dot notation in a lightweight and fast way. Inspired by Laravel Collection.

Dot implements PHP's ArrayAccess interface and Dot object can also be used the same way as normal arrays with additional dot notation.

Examples
--------

[](#examples)

With Dot you can change this regular array syntax:

```
$array['info']['home']['address'] = 'Kings Square';

echo $array['info']['home']['address'];

// Kings Square
```

to this (Dot object):

```
$dot->set('info.home.address', 'Kings Square');

echo $dot->get('info.home.address');
```

or even this (ArrayAccess):

```
$dot['info.home.address'] = 'Kings Square';

echo $dot['info.home.address'];
```

Install
-------

[](#install)

Install the latest version using [Composer](https://getcomposer.org/):

```
composer require adbario/php-dot-notation

```

Usage
-----

[](#usage)

Create a new Dot object:

```
$dot = new \Adbar\Dot;

// With existing array
$dot = new \Adbar\Dot($array);

// Or with auto parsing dot notation keys in existing array
$dot = new \Adbar\Dot($array, true);

// You can also set a custom delimiter instead of the default dot (.)
$dot = new \Adbar\Dot($array, false, "_");
```

You can also use a helper function to create the object:

```
$dot = dot();

// With existing array
$dot = dot($array);

// Or with auto parsing dot notation keys in existing array
$dot = dot($array, true);

// You can also set a custom delimiter instead of the default dot (.)
$dot = dot($array, true, "_");
```

All methods not returning a specific value returns the Dot object for chaining:

```
$dot = dot();

$dot->add('user.name', 'John')
    ->set('user.email', 'john@example.com')
    ->clear(); // returns empty Dot
```

Methods
-------

[](#methods)

Dot has the following methods:

- [add()](#add)
- [all()](#all)
- [clear()](#clear)
- [count()](#count)
- [delete()](#delete)
- [flatten()](#flatten)
- [get()](#get)
- [has()](#has)
- [isEmpty()](#isempty)
- [merge()](#merge)
- [mergeRecursive()](#mergerecursive)
- [mergeRecursiveDistinct()](#mergerecursivedistinct)
- [pull()](#pull)
- [push()](#push)
- [replace()](#replace)
- [set()](#set)
- [setArray()](#setarray)
- [setReference()](#setreference)
- [toJson()](#tojson)

### add()

[](#add)

Sets a given key / value pair if the key doesn't exist already:

```
$dot->add('user.name', 'John');

// Equivalent vanilla PHP
if (!isset($array['user']['name'])) {
    $array['user']['name'] = 'John';
}
```

Multiple key / value pairs:

```
$dot->add([
    'user.name' => 'John',
    'page.title' => 'Home'
]);
```

### all()

[](#all)

Returns all the stored items as an array:

```
$values = $dot->all();
```

### clear()

[](#clear)

Deletes the contents of a given key (sets an empty array):

```
$dot->clear('user.settings');

// Equivalent vanilla PHP
$array['user']['settings'] = [];
```

Multiple keys:

```
$dot->clear(['user.settings', 'app.config']);
```

All the stored items:

```
$dot->clear();

// Equivalent vanilla PHP
$array = [];
```

### count()

[](#count)

Returns the number of items in a given key:

```
$dot->count('user.siblings');
```

Items in the root of Dot object:

```
$dot->count();

// Or use count() function as Dot implements Countable
count($dot);
```

### delete()

[](#delete)

Deletes the given key:

```
$dot->delete('user.name');

// ArrayAccess
unset($dot['user.name']);

// Equivalent vanilla PHP
unset($array['user']['name']);
```

Multiple keys:

```
$dot->delete([
    'user.name',
    'page.title'
]);
```

### flatten()

[](#flatten)

Returns a flattened array with the keys delimited by a given character (default "."):

```
$flatten = $dot->flatten();
```

### get()

[](#get)

Returns the value of a given key:

```
echo $dot->get('user.name');

// ArrayAccess
echo $dot['user.name'];

// Equivalent vanilla PHP < 7.0
echo isset($array['user']['name']) ? $array['user']['name'] : null;

// Equivalent vanilla PHP >= 7.0
echo $array['user']['name'] ?? null;
```

Returns a given default value, if the given key doesn't exist:

```
echo $dot->get('user.name', 'some default value');
```

### has()

[](#has)

Checks if a given key exists (returns boolean true or false):

```
$dot->has('user.name');

// ArrayAccess
isset($dot['user.name']);
```

Multiple keys:

```
$dot->has([
    'user.name',
    'page.title'
]);
```

### isEmpty()

[](#isempty)

Checks if a given key is empty (returns boolean true or false):

```
$dot->isEmpty('user.name');

// ArrayAccess
empty($dot['user.name']);

// Equivalent vanilla PHP
empty($array['user']['name']);
```

Multiple keys:

```
$dot->isEmpty([
    'user.name',
    'page.title'
]);
```

Checks the whole Dot object:

```
$dot->isEmpty();
```

### merge()

[](#merge)

Merges a given array or another Dot object:

```
$dot->merge($array);

// Equivalent vanilla PHP
array_merge($originalArray, $array);
```

Merges a given array or another Dot object with the given key:

```
$dot->merge('user', $array);

// Equivalent vanilla PHP
array_merge($originalArray['user'], $array);
```

### mergeRecursive()

[](#mergerecursive)

Recursively merges a given array or another Dot object:

```
$dot->mergeRecursive($array);

// Equivalent vanilla PHP
array_merge_recursive($originalArray, $array);
```

Recursively merges a given array or another Dot object with the given key:

```
$dot->mergeRecursive('user', $array);

// Equivalent vanilla PHP
array_merge_recursive($originalArray['user'], $array);
```

### mergeRecursiveDistinct()

[](#mergerecursivedistinct)

Recursively merges a given array or another Dot object. Duplicate keys overwrite the value in the original array (unlike [mergeRecursive()](#mergerecursive), where duplicate keys are transformed into arrays with multiple values):

```
$dot->mergeRecursiveDistinct($array);
```

Recursively merges a given array or another Dot object with the given key. Duplicate keys overwrite the value in the original array.

```
$dot->mergeRecursiveDistinct('user', $array);
```

### pull()

[](#pull)

Returns the value of a given key and deletes the key:

```
echo $dot->pull('user.name');

// Equivalent vanilla PHP < 7.0
echo isset($array['user']['name']) ? $array['user']['name'] : null;
unset($array['user']['name']);

// Equivalent vanilla PHP >= 7.0
echo $array['user']['name'] ?? null;
unset($array['user']['name']);
```

Returns a given default value, if the given key doesn't exist:

```
echo $dot->pull('user.name', 'some default value');
```

Returns all the stored items as an array and clears the Dot object:

```
$items = $dot->pull();
```

### push()

[](#push)

Pushes a given value to the end of the array in a given key:

```
$dot->push('users', 'John');

// Equivalent vanilla PHP
$array['users'][] = 'John';
```

Pushes a given value to the end of the array:

```
$dot->push('John');

// Equivalent vanilla PHP
$array[] = 'John';
```

### replace()

[](#replace)

Replaces the values with values having the same keys in the given array or Dot object:

```
$dot->replace($array);

// Equivalent vanilla PHP
array_replace($originalArray, $array);
```

Replaces the values with values having the same keys in the given array or Dot object with the given key:

```
$dot->merge('user', $array);

// Equivalent vanilla PHP
array_replace($originalArray['user'], $array);
```

`replace()` is not recursive.

### set()

[](#set)

Sets a given key / value pair:

```
$dot->set('user.name', 'John');

// ArrayAccess
$dot['user.name'] = 'John';

// Equivalent vanilla PHP
$array['user']['name'] = 'John';
```

Multiple key / value pairs:

```
$dot->set([
    'user.name' => 'John',
    'page.title'     => 'Home'
]);
```

### setArray()

[](#setarray)

Replaces all items in Dot object with a given array:

```
$dot->setArray($array);
```

### setReference()

[](#setreference)

Replaces all items in Dot object with a given array as a reference and all future changes to Dot will be made directly to the original array:

```
$dot->setReference($array);
```

### toJson()

[](#tojson)

Returns the value of a given key as JSON:

```
echo $dot->toJson('user');
```

Returns all the stored items as JSON:

```
echo $dot->toJson();
```

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

[](#contributing)

### Pull Requests

[](#pull-requests)

1. Fork the Dot repository
2. Create a new branch for each feature or improvement
3. Send a pull request from each feature branch to the 3.x branch

It is very important to separate new features or improvements into separate feature branches, and to send a pull request for each branch. This allows me to review and pull in new features or improvements individually.

### Style Guide

[](#style-guide)

All pull requests must adhere to the [PSR-12 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md).

### Unit Testing

[](#unit-testing)

All pull requests must be accompanied by passing unit tests and complete code coverage. Dot uses [PHPUnit](https://github.com/sebastianbergmann/phpunit/) for testing.

### Static Analysis

[](#static-analysis)

All pull requests must pass static analysis using [PHPStan](https://github.com/sebastianbergmann/phpunit/).

License
-------

[](#license)

[MIT license](LICENSE.md)

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance54

Moderate activity, may be stable

Popularity66

Solid adoption and visibility

Community44

Growing community involvement

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 89.3% 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 ~171 days

Recently: every ~302 days

Total

21

Last Release

104d ago

Major Versions

1.x-dev → 2.0.02017-09-22

2.2.0 → 3.0.02022-03-25

2.5.0 → 3.2.02022-10-15

PHP version history (4 changes)1.2.0PHP &gt;=5.4

2.0.0PHP &gt;=5.5

3.0.0PHP ^7.4 || ^8.0

2.4.0PHP ^5.5 || ^7.0 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22136575?v=4)[Riku Sarkinen](/maintainers/adbario)[@adbario](https://github.com/adbario)

---

Top Contributors

[![adbario](https://avatars.githubusercontent.com/u/22136575?v=4)](https://github.com/adbario "adbario (108 commits)")[![vanodevium](https://avatars.githubusercontent.com/u/16780069?v=4)](https://github.com/vanodevium "vanodevium (3 commits)")[![melbings](https://avatars.githubusercontent.com/u/15344864?v=4)](https://github.com/melbings "melbings (2 commits)")[![nicoorfi](https://avatars.githubusercontent.com/u/15706832?v=4)](https://github.com/nicoorfi "nicoorfi (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![qaharmdz](https://avatars.githubusercontent.com/u/707089?v=4)](https://github.com/qaharmdz "qaharmdz (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![gmsantos](https://avatars.githubusercontent.com/u/1991286?v=4)](https://github.com/gmsantos "gmsantos (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (1 commits)")

---

Tags

arrayaccessdot-notationphpArrayAccessdotnotation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/adbario-php-dot-notation/health.svg)

```
[![Health](https://phpackages.com/badges/adbario-php-dot-notation/health.svg)](https://phpackages.com/packages/adbario-php-dot-notation)
```

###  Alternatives

[ayesh/case-insensitive-array

Class to store and access data in a case-insensitive fashion, while maintaining the integrity and functionality of a regular array.

1020.7k3](/packages/ayesh-case-insensitive-array)[rotexsoft/versatile-collections

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

186.0k1](/packages/rotexsoft-versatile-collections)[mainwp/mainwp-child

This is the Child plugin for the MainWP Dashboard

973.4k](/packages/mainwp-mainwp-child)

PHPackages © 2026

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