PHPackages                             binary-cube/dot-array - 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. binary-cube/dot-array

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

binary-cube/dot-array
=====================

PHP Dot-Array :: Sail through array using the dot notation

1.1.0(7y ago)10107.7k↑19.6%11MITPHPPHP &gt;=7.1CI failing

Since Dec 25Pushed 6y ago3 watchersCompare

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

READMEChangelog (7)Dependencies (4)Versions (8)Used By (1)

PHP Dot-Array :: Sail through array using the dot notation
==========================================================

[](#php-dot-array--sail-through-array-using-the-dot-notation)

~ Enjoy your ☕ ~

Accessing PHP Arrays via DOT notation is easy as:

```
DotArray::create(['config' => ['some.dotted.key' => 'value']])->get('config.{some.dotted.key}')
```

[![Minimum PHP Version PHP >= 7.1](https://camo.githubusercontent.com/dcd4b4aec2c1709157fa6a2c050f709d75cde9552a79cfff0b70a97fad7281ae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Latest Stable Version](https://camo.githubusercontent.com/6c176fec3d95995cb7b6f6bb2fdd01db07fd9e60fb0eea78821c9d8bde91b4fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62696e6172792d637562652f646f742d61727261792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/binary-cube/dot-array)[![Total Downloads](https://camo.githubusercontent.com/e81e40b7dc52dba257fa237360cc4518ff2b50beb8d50e7c78b74f60b1c9f949/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62696e6172792d637562652f646f742d61727261792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/binary-cube/dot-array)[![Build Status](https://camo.githubusercontent.com/087c492226f7c8d531d489ac20bdf5fc281deba7a22dc61ac8f7a08ac5a1f35f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62696e6172792d637562652f646f742d61727261792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/binary-cube/dot-array)[![Code Coverage](https://camo.githubusercontent.com/b652ff956d79144d9a53b3228b67f3eab011041afd6bf2f1f57b84f241cf56d9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f62696e6172792d637562652f646f742d61727261792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/binary-cube/dot-array/code-structure)[![Quality Score](https://camo.githubusercontent.com/12a6ac46b9e1fb5faf92c1d3ad4e115520b0002c5f882b9cd380de38ee65f9e4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62696e6172792d637562652f646f742d61727261792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/binary-cube/dot-array)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/binary-cube/dot-array/blob/master/LICENSE)

---

Installing
----------

[](#installing)

- **via "composer require"**:

    ```
    composer require binary-cube/dot-array
    ```
- **via composer (manually)**:

    If you're using Composer to manage dependencies, you can include the following in your `composer.json` file:

    ```
    {
        "require": {
            "binary-cube/dot-array": "1.*"
        }
    }
    ```

Usage
-----

[](#usage)

> ##### REMEMBER: YOU NEED TO KNOW YOUR DATA
>
> [](#remember-you-need-to-know-your-data)
>
> ##### DotArray::get() can return a new instance of DotArray in case the accessed path is an array or it will return the raw data value or the default given value
>
> [](#dotarrayget-can-return-a-new-instance-of-dotarray-in-case-the-accessed-path-is-an-array-or-it-will-return-the-raw-data-value-or-the-default-given-value)

- **instantiation**:

    - ```
        new DotArray($array);
        DotArray::create($array);
        DotArray::createFromJson($jsonString);
        ```
- **get**:

    - ```
        // Because the key `sci-fi & fantasy` is array the returning value it will be a new instance of DotArray.
        $dot('books.{sci-fi & fantasy}');

        // Because the price is not an array, the result will be raw data, float in this case.
        $dot('books.{sci-fi & fantasy}.0.price');

        // Accessing the raw array.
        $dot('books.{sci-fi & fantasy}')->toArray();
        $dot->get('books.{sci-fi & fantasy}')->toArray();

        // Accessing the last leaf and getting the raw data.
        $dot('books.{sci-fi & fantasy}.0.name');
        $dot->get('books.{sci-fi & fantasy}.0.name');

        // Giving a default value in case the requested key is not found.
        $dot->get('key.not.exist', 'not-found-as-string');

        // Vanilla PHP.
        $dot('books.{sci-fi & fantasy}.0.name');
        $dot['books']['sci-fi & fantasy'][0]['name'];
        ```
- **get :: more-complex**:

    - ```
        // Using dotted key and accessing without getting confused.
        // Allowed tokens for keeping the names with dot(.) togethers are: '', "", [], (), {}
        $dot->get('config.{elastic-search}.\'v5.0\'.host')
        $dot->get('config.{elastic-search}."v5.0".host')
        $dot->get('config.{elastic-search}.[v5.0].host')
        $dot->get('config.{elastic-search}.(v5.0).host')
        $dot->get('config.{elastic-search}.{v5.0}.host')
        ```
- **set**:

    - ```
        $dot->set('books.{sci-fi & fantasy}.0.name', 'New Name');

        // Vanilla PHP.
        $dot['books.{sci-fi & fantasy}.0.name'] = 'New Name';
        $dot['books']['sci-fi & fantasy'][0]['name'] = 'New Name';
        ```
- **clear** *(empty array &lt;=&gt; \[\])*:

    > Set the contents of a given key or keys to the given value (default is empty array).

    - ```
        $dot->clear('books.{sci-fi & fantasy}');
        $dot->clear('books.{sci-fi & fantasy}', null);
        $dot->clear('books.{sci-fi & fantasy}.0.name', null);

        // Multiple keys.
        $dot->clear([
          'books.{sci-fi & fantasy}',
          'books.{children\'s books}'
        ]);

        // Vanilla PHP.
        $dot['books.{sci-fi & fantasy}'] = [];
        ```
- **delete** *(unset(...))*:

    > Delete the given key or keys.

    - ```
        $dot->delete('books.{sci-fi & fantasy}');
        $dot->delete('books.{sci-fi & fantasy}.0.name');
        $dot->delete(['books.{sci-fi & fantasy}.0', 'books.{children\'s books}.0']);
        ```
- **merge**:

    > Merges one or more arrays into master recursively.
    > If each array has an element with the same string key value, the latter will overwrite the former (different from array\_merge\_recursive).
    > Recursive merging will be conducted if both arrays have an element of array type and are having the same key.
    > For integer-keyed elements, the elements from the latter array will be appended to the former array.

    - ```
        // Example 1.
        $dot->merge(['key_1' => ['some_key' => 'some_value']]);

        // Example 2.
        $dot->merge(
            [
                'key_1' => ['some_key' => 'some_value'],
            ],
            [
                'key_2' => ['some_key' => 'some_value'],
            ],
            [
                'key_n' => ['some_key' => 'some_value']
            ],
        );
        ```
- **find**:

    > Find the first item in an array that passes the truth test, otherwise return false.
    > The signature of the callable must be: `function ($value, $key)`.

    - ```
        $book = $dot->get('books.{children\'s books}')->find(function ($value, $key) {
           return $value['price'] > 0;
        });
        ```
- **filter**:

    > Use a callable function to filter through items.
    > The signature of the callable must be: `function ($value, $key)`

    - ```
        $books = $dot->get('books.{children\'s books}')->filter(function ($value, $key) {
            return $value['name'] === 'Harry Potter and the Order of the Phoenix';
        });

        $books->toArray();
        ```
- **filterBy**:

    - ```
        /*
            Allowed comparison operators:
                - [ =, ==, eq (equal) ]
                - [ ===, i (identical) ]
                - [ !=, ne (not equal) ]
                - [ !==, ni (not identical) ]
                - [ , gr (greater than) ]
                - [ , gte (greater than or equal to) ]
                - [ in, contains ]
                - [ not-in, not-contains ]
                - [ between ]
                - [ not-between ]
        */
        // Example 1.
        $books = $dot->get('books.{children\'s books}')->filterBy('price', 'between', 5, 12);

        // Example 2.
        $books = $dot->get('books.{children\'s books}')->filterBy('price', '>', 10);

        // Example 3.
        $books = $dot->get('books.{children\'s books}')->filterBy('price', 'in', [8.5, 15.49]);
        ```
- **where**:

    - ```
        /*
            The signature of the `where` call can be:
                - where([property, comparisonOperator, ...value])
                - where(\Closure) :: The signature of the callable must be: `function ($value, $key)`

            Allowed comparison operators:
                - [ =, ==, eq (equal) ]
                - [ ===, i (identical) ]
                - [ !=, ne (not equal) ]
                - [ !==, ni (not identical) ]
                - [ , gr (greater than) ]
                - [ , gte (greater than or equal to) ]
                - [ in, contains ]
                - [ not-in, not-contains ]
                - [ between ]
                - [ not-between ]
        */

        // Example 1. (using the signature: [property, comparisonOperator, ...value])
        $books = $dot->get('books.{children\'s books}')->where(['price', 'between', 5, 12]);

        // Example 2. (using the signature: [property, comparisonOperator, ...value])
        $books = $dot->get('books.{children\'s books}')->where(['price', '>', 10]);

        // Example 3. (using the signature: [property, comparisonOperator, ...value])
        $books = $dot->get('books.{children\'s books}')->where(['price', 'in', [8.5, 15.49]]);

        // Example 4. (using the signature: \Closure)
        $books = $dot->get('books.{children\'s books}')->where(function ($value, $key) {
            return $value['name'] === 'Harry Potter and the Order of the Phoenix';
        });
        ```
- **toArray**:

    > Getting the internal raw array.

    - ```
        // Example 1.
        $dot->toArray();

        // Example 2.
        $dot->get('books.{sci-fi & fantasy}')->toArray();
        ```
- **toJson**:

    > Getting the internal raw array as JSON.

    - ```
        // Example 1.
        $dot->toJson();

        // Example 2.
        $dot->get('books.{sci-fi & fantasy}')->toJson();
        ```
- **toFlat**:

    > Flatten the internal array using the dot delimiter, also the keys are wrapped inside {key} (1 x curly braces).

    - ```
        $dot = DotArray::create(
            [
                'a' => [
                    'b' => 'value',
                ],

                'b' => [
                    1,
                    2,
                    3,
                    'array' => [
                        1,
                        2,
                        3,
                    ]
                ],
            ]
        );

        $dot->toFlat();

        /*
            The output will be an array:
            [
                '{a}.{b}' => 'value',
                '{b}.{0}' => 1,
                '{b}.{1}' => 2,
                '{b}.{2}' => 3,
                '{b}.{array}.{0}' => 1,
                '{b}.{array}.{1}' => 2,
                '{b}.{array}.{2}' => 3,
            ],
        */
        ```

### Data Sample:

[](#data-sample)

```
$dummyArray = [
    'books' => [
        'sci-fi & fantasy' =>
            [
                [
                    'name'      => 'Chronicles of Narnia Box Set',
                    'price'     => 24.55,
                    'currency'  => '$',
                    'authors'   =>
                        [
                            [
                                'name' => 'C.S. Lewis'
                            ],
                        ],
                ],
                [
                    'name'      => 'A Game of Thrones / A Clash of Kings / A Storm of Swords / A Feast of Crows / A Dance with Dragons ',
                    'price'     => 37.97,
                    'currency'  => '$',
                    'authors'   =>
                        [
                            [
                                'name' => 'George R. R. Martin'
                            ],
                         ],
                ],
            ],

        'children\'s books' =>
            [
                [
                    'name'      => 'Harry Potter and the Order of the Phoenix',
                    'price'     => 15.49,
                    'currency'  => '$',
                    'authors'   =>
                        [
                            [
                                'name' => 'J. K. Rowling'
                            ],
                        ],
                ],
                [
                    'name'      => 'Harry Potter and the Cursed Child',
                    'price'     => 8.5,
                    'currency'  => '$',
                    'authors'   =>
                        [
                            [
                                'name' => 'J. K. Rowling',
                            ],
                            [
                                'name' => 'Jack Thorne'
                            ],
                        ],
                ],
            ],

    ],
];
```

Bugs and feature requests
-------------------------

[](#bugs-and-feature-requests)

Have a bug or a feature request? Please first read the issue guidelines and search for existing and closed issues. If your problem or idea is not addressed yet, [please open a new issue](https://github.com/binary-cube/dot-array/issues/new).

Contributing guidelines
-----------------------

[](#contributing-guidelines)

All contributions are more than welcomed. Contributions may close an issue, fix a bug (reported or not reported), add new design blocks, improve the existing code, add new feature, and so on. In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. [Read the full Code of Conduct](https://github.com/binary-cube/dot-array/blob/master/code-of-conduct.md).

#### Versioning

[](#versioning)

Through the development of new versions, we're going use the [Semantic Versioning](https://semver.org).

Example: `1.0.0`.

- Major release: increment the first digit and reset middle and last digits to zero. Introduces major changes that might break backward compatibility. E.g. 2.0.0
- Minor release: increment the middle digit and reset last digit to zero. It would fix bugs and also add new features without breaking backward compatibility. E.g. 1.1.0
- Patch release: increment the third digit. It would fix bugs and keep backward compatibility. E.g. 1.0.1

Authors
-------

[](#authors)

- **Banciu N. Cristian Mihai**

See also the list of [contributors](https://github.com/binary-cube/dot-array/graphs/contributors) who participated in this project.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](https://github.com/binary-cube/dot-array/blob/master/LICENSE) file for details.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

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 ~11 days

Total

7

Last Release

2635d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/327b21f2438fba2a3f8b19c9b4cc667773a62b6fa0e61216d38f45d9d4464014?d=identicon)[microThread](/maintainers/microThread)

---

Top Contributors

[![microThread](https://avatars.githubusercontent.com/u/4279940?v=4)](https://github.com/microThread "microThread (61 commits)")

---

Tags

arrayarray-helperarray-manipulationsarraysdotdot-arraydot-notationdotarrayphpphp7arraydotdotarrayphp-arraydot-arrayphp-array-json-path

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/binary-cube-dot-array/health.svg)

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

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[dflydev/dot-access-data

Given a deep data structure, access data by dot notation.

720359.1M86](/packages/dflydev-dot-access-data)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)

PHPackages © 2026

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