PHPackages                             noj/dot - 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. noj/dot

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

noj/dot
=======

Nested array/object access through dot notation

1.2.0(6mo ago)49.8k↓100%1MITPHPPHP ^8.0CI passing

Since Apr 23Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/jonnyynnoj/dot)[ Packagist](https://packagist.org/packages/noj/dot)[ RSS](/packages/noj-dot/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (10)Used By (1)

Dot
===

[](#dot)

[![Travis (.com)](https://camo.githubusercontent.com/3fc1b28d30ee4745bbb62bc2af9ab958f25908b0eb4cef9d59aaa03c6c6088f4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6a6f6e6e79796e6e6f6a2f646f743f7374796c653d666c61742d737175617265)](https://travis-ci.com/github/jonnyynnoj/dot)[![Latest Stable Version](https://camo.githubusercontent.com/005f1aaaff48300bdfd614738b1eb41765fb1f330328a166a025181a29904024/68747470733a2f2f706f7365722e707567782e6f72672f6e6f6a2f646f742f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/noj/dot)[![PHP Version Support](https://camo.githubusercontent.com/ff890976fc5a9609959b0bfdbe509d3b561e4c3b95fa100919a31f1178d2c74d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e6f6a2f646f743f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ff890976fc5a9609959b0bfdbe509d3b561e4c3b95fa100919a31f1178d2c74d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e6f6a2f646f743f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/6a1e36947b94f63a2443caa02c6a3acea7908fff8721b7cc8d6cdef979bcb92c/68747470733a2f2f706f7365722e707567782e6f72672f6e6f6a2f646f742f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/noj/dot)[![Total Downloads](https://camo.githubusercontent.com/9e84f86138a901b6f590095ec056d5113e48647a130fbc1332cbfeff08d79745/68747470733a2f2f706f7365722e707567782e6f72672f6e6f6a2f646f742f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/noj/dot)

Dot allows you to get &amp; set array keys or object properties using dot notation.

Installing
----------

[](#installing)

```
composer require noj/dot
```

Usage
-----

[](#usage)

First construct a new Dot instance:

```
$dot = new Dot($data);
$dot = Dot::from($data); // alternative
```

All the examples are using the following data structure unless otherwise specified:

```
$data = [
    'groups' => [
        (object)[
            'name' => 'group1',
            'items' => [
                [
                    'name' => 'item1',
                    'rare' => false,
                ],
                [
                    'name' => 'item3',
                    'rare' => true,
                ],
            ]
        ],
        (object)[
            'name' => 'group2',
            'items' => []
        ],
        (object)[
            'name' => 'group3',
            'items' => [
                [
                    'name' => 'item2',
                    'rare' => true,
                ],
            ]
        ],
    ]
];
```

### Methods

[](#methods)

- [count](#dotcountstring-path-int)
- [find](#dotfindstring-path-mixed-equals-dot)
- [first](#dotfirststring-path-mixed-equals-dot)
- [get](#dotgetnullintstring-path-mixed)
- [has](#dothasstring-path-bool)
- [push](#dotpushstring-path-mixed-value-dot)
- [set](#dotsetarraystring-paths-mixed-value-void)

#### `Dot::count(string $path): int`

[](#dotcountstring-path-int)

Count the number of items at a given path.

```
$dot->count('groups.0.items'); // 2
$dot->count('groups.*.items'); // 3
```

#### `Dot::find(string $path, mixed $equals): Dot`

[](#dotfindstring-path-mixed-equals-dot)

Find items that pass the given truth test.

```
// find where property === value
$dot->find('groups.*.items.*.rare', true)->get();
/*
[
    ['name' => 'item3', 'rare' => true],
    ['name' => 'item2', 'rare' => true],
]
*/

// pass a callback for custom comparisons
$dot->find('groups.*.items.*.name', function (string $name) {
    return $name === 'item2' || $name === 'item3';
})->get(); // returns same as above

// leave off the property to receive the whole item
$dot->find('groups.*.items.*', function (array $item) {
    return $item['name'] === 'item3' && $item['rare'];
})->get();
```

#### `Dot::first(string $path, mixed $equals): Dot`

[](#dotfirststring-path-mixed-equals-dot)

Find the first item that passes the given truth test.

```
$dot->first('groups.*.items.*.rare', true)->get(); // ['name' => 'item3', 'rare' => true]

$dot->first('groups.*.items.*', fn (array $item) => $item['rare'] === true)->get(); // same as above
```

#### `Dot::get(null|int|string $path): mixed`

[](#dotgetnullintstring-path-mixed)

Access nested array keys and object properties using dot syntax:

```
$dot->get('groups.0.items.1.name'); // 'item3'
```

Dot safely returns null if the key or property doesn't exist:

```
$dot->get('groups.3.items.1.name'); // null
```

You can use a wildcard `*` to pluck values from multiple paths:

```
$dot->get('groups.*.items.*.name'); // ['item1', 'item3', 'item2']

$dot->get('groups.*.items'); /* [
    ['name' => 'item1', 'rare' => false],
    ['name' => 'item3', 'rare' => true],
    ['name' => 'item2', 'rare' => true],
] */
```

You can call functions using the `@` prefix:

```
$data = [
    'foo' => new class {
        public function getBar() {
            return ['bar' => 'value'];
        }
    }
];

(new Dot($data))->get('foo.@getBar.bar'); // 'value'
```

If no argument is passed it will return the underlying data:

```
$dot->get() === $data; // true
```

#### `Dot::has(string $path): bool`

[](#dothasstring-path-bool)

Returns true if path exists, false otherwise:

```
$dot->has('groups.0.items.1.name'); // true
```

#### `Dot::push(string $path, mixed $value): Dot`

[](#dotpushstring-path-mixed-value-dot)

Push a value onto an existing array:

```
$dot->push('groups.0.items', ['name' => 'another item']);

// supports wildcards
$dot->push('groups.*.items', ['name' => 'another item']);
```

#### `Dot::set(array|string $paths, mixed $value): void`

[](#dotsetarraystring-paths-mixed-value-void)

You can set nested values using the same syntax:

```
$dot->set('groups.2.items.0.name', 'a different name');
echo $data['groups'][2]->items[0]['name']; // 'a different name'
```

Set nested keys from multiple paths using a wildcard `*`:

```
$dot->set('groups.*.items.*.name', 'set all to same name');
```

Keys will be created if they don't already exist:

```
$dot->set('groups.0.items.2.name', 'a new item');
```

By default, set will initialise missing values as empty arrays. To indicate that something should be an object use the `->` delimiter:

```
$dot->set('groups.3->items.2.name', 'a new item');
```

You can set multiple values at once by passing an array:

```
$dot->set([
    'groups.0.items.1.name' => 'something',
    'groups.2.items.0.name' => 'something else',
]):
```

You can call a method:

```
$data = [
    'foo' => new class {
        public $bars = [];
        public function addBar($bar) {
            $this->bar[] = $bar;
        }
    }
];

$dot = new Dot($data);
$dot->set('foo.@addBar', 'value');
echo $data['foo']->bars; // ['value']
```

Or call a method for each value of an array:

```
$dot->set('foo.@addBar*', ['value1', 'value2']);
echo $data['foo']->bars; // ['value1', 'value2']
```

### Non-chained versions

[](#non-chained-versions)

All methods have non-chained versions of themselves as a standalone function, i.e:

```
// instead of
$filtered = \Noj\Dot\Dot::from($data)
    ->find('groups.*.items.*.rare', true)
    ->get();

// you can do
$filtered = \Noj\Dot\find($data, 'groups.*.items.*.rare', true');
```

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance66

Regular maintenance activity

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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

Every ~285 days

Recently: every ~499 days

Total

8

Last Release

206d ago

Major Versions

0.0.4 → 1.0.02020-05-11

PHP version history (3 changes)0.0.1PHP ^7.0

1.0.1PHP ^7.0|^8.0

1.1.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d369a62e418f4117468a6f044463f3d29182f67d876996c3f65d41e6e85a312?d=identicon)[jonnyynnoj](/maintainers/jonnyynnoj)

---

Top Contributors

[![jonnyynnoj](https://avatars.githubusercontent.com/u/1348288?v=4)](https://github.com/jonnyynnoj "jonnyynnoj (79 commits)")

---

Tags

dot-notationdotnotationphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/noj-dot/health.svg)

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

PHPackages © 2026

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