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

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

firstred/php-dot-notation
=========================

PHP dot notation access to arrays

2.0.2(7y ago)0129MITPHPPHP &gt;=5.3.3

Since Sep 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/firstred/php-dot-notation)[ Packagist](https://packagist.org/packages/firstred/php-dot-notation)[ Docs](https://github.com/adbario/php-dot-notation)[ RSS](/packages/firstred-php-dot-notation/feed)WikiDiscussions 2.x Synced today

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

Dot - PHP dot notation access to arrays
=======================================

[](#dot---php-dot-notation-access-to-arrays)

[![Build Status](https://camo.githubusercontent.com/2ba09e0a6806cbdc909e4f035ace47bace023cbf57ae5e719cc2468cab884d12/68747470733a2f2f7472617669732d63692e6f72672f6164626172696f2f7068702d646f742d6e6f746174696f6e2e7376673f6272616e63683d322e78)](https://travis-ci.org/adbario/php-dot-notation)[![Coverage Status](https://camo.githubusercontent.com/a67937a18b1e1e3ba03fb99fb5ee3bf2def764f098a81deb085240509143b272/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6164626172696f2f7068702d646f742d6e6f746174696f6e2f62616467652e7376673f6272616e63683d322e78)](https://coveralls.io/github/adbario/php-dot-notation?branch=2.x)[![Total Downloads](https://camo.githubusercontent.com/f051d806ae8afe864601b73ef1bb990104f113906e3b88a7a43c884c010d278d/68747470733a2f2f706f7365722e707567782e6f72672f6164626172696f2f7068702d646f742d6e6f746174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/adbario/php-dot-notation)[![License](https://camo.githubusercontent.com/336614e1ea4721e4e3fbd2dc7c578062f61c4991df6e26296bea002713fafdf5/68747470733a2f2f706f7365722e707567782e6f72672f6164626172696f2f7068702d646f742d6e6f746174696f6e2f6c6963656e7365)](LICENSE.md)

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 chage 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);
```

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

```
$dot = dot();

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

Methods
-------

[](#methods)

Dot has the following methods:

- [add()](#add)
- [all()](#all)
- [clear()](#clear)
- [count()](#count)
- [delete()](#delete)
- [get()](#get)
- [has()](#has)
- [isEmpty()](#isEmpty)
- [merge()](#merge)
- [pull()](#pull)
- [push()](#push)
- [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 coun() 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'
]);
```

### 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);
```

### 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';
```

### 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();
```

License
-------

[](#license)

[MIT license](LICENSE.md)

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 90.7% 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 ~128 days

Recently: every ~177 days

Total

8

Last Release

2575d ago

Major Versions

1.x-dev → 2.0.02017-09-22

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

2.0.0PHP &gt;=5.5

2.0.2PHP &gt;=5.3.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/19a7ae32d0ed2d82460029f3f303d28c45938b05cd03fe67807cabdfbaa93b53?d=identicon)[firstred](/maintainers/firstred)

---

Top Contributors

[![adbario](https://avatars.githubusercontent.com/u/22136575?v=4)](https://github.com/adbario "adbario (39 commits)")[![firstred](https://avatars.githubusercontent.com/u/6775736?v=4)](https://github.com/firstred "firstred (4 commits)")

---

Tags

ArrayAccessdotnotation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[adbario/php-dot-notation

PHP dot notation access to arrays

4638.6M165](/packages/adbario-php-dot-notation)[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.

185.9k1](/packages/rotexsoft-versatile-collections)[cornford/googlitics

An easy way to integrate Google Analytics with Laravel.

3210.2k](/packages/cornford-googlitics)

PHPackages © 2026

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