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

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

jbizzay/php-dot
===============

Structured array helper with dot notation

v0.5(8y ago)1252[1 issues](https://github.com/jkuchynka/php-dot/issues)MITPHP

Since Apr 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jkuchynka/php-dot)[ Packagist](https://packagist.org/packages/jbizzay/php-dot)[ RSS](/packages/jbizzay-php-dot/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

PHP Dot Array
=============

[](#php-dot-array)

This repo is unmaintained. Check out this if you need something simliar:

Helps manage arrays in PHP with dot notation. Useful for configs, meta data, or just working with large associative arrays.

Often, working with large arrays is cumbersome and prone to errors. Having to drill down into multiple levels of an array, checking isset all the way, is not fun.

```
if (isset($data['level1']) && isset($data['level1']['level2'])) {
    $value = $data['level1']['level2']['key'];
} else {
    $value = null;
}
```

Instead, you can do this:

```
$dot = new Dot($data);
$value = $dot->get('level1.level2.key');
```

It will simply return null, instead of throwing an undefined index error, if any part of the dot path doesn't exist. Also, working with dot notation makes code more readable and easier to write.

Usage
-----

[](#usage)

### Create a Dot

[](#create-a-dot)

```
use Jbizzay\Dot;

// Create empty dot
$dot = new Dot;

// Or, initialize with an array of data
$data = [
  'stats' => [
    'web' => [
      'hits' => 99
    ],
    'mobile' => [

    ]
  ]
];

$dot = new Dot($data);
```

### Get

[](#get)

With no argument, get returns the entire data array. Pass a dot notation string to access parts of the data array.

```
$dot->get(); // Returns full data array

$dot->get('stats.web.hits'); // Returns 99

$dot->get('stats.mobile.hits'); // Returns null

$dot->get('some.random.undefined.key'); // Returns null

```

### Set

[](#set)

You can set any data type, including callable functions. Any levels that don't already exist, will be created as associative arrays. Set returns the same instance of Dot allowing for method chaining. Using a callable type will recieve the currently set value (if it exists) as an argument.

```
$dot
  ->set('stats.web.last_updated', new DateTime)
  ->set('stats.web.allow_tracking', true)
  ->set('stats.web.hits', function ($hits) {
    $hits++;
    return $hits;
  });

$dot->get('stats.web');

/* Returns:
Array
(
    [hits] => 100
    [last_updated] => DateTime Object
        (
            [date] => 2017-07-21 14:50:34.000000
            [timezone_type] => 3
            [timezone] => America/Los_Angeles
        )

    [allow_tracking] => 1
)
*/
```

### Unset

[](#unset)

Unset a value, returns the dot instance

```
$dot
  ->unset('path.to.value')
  ->unset('some.other.value');
```

### Has

[](#has)

Determines if a key is set

```
$dot->has('stats.web'); // true
$dot->has('some.random.key'); // false
```

### Define

[](#define)

Gets a value, but if the key is not set, initialize the key with a value. You can also use a callable type. By default, initializes with array. Returns the dot path value

```
$dot->define('leads.emails'); // Sets to an array
$hits = $dot->define('stats.mobile.hits', 0);
$dot->define('stats.console.hits', function () {
  // This function is called if this key is not set yet
  return 0;
});
```

### Merge

[](#merge)

Recursively merges an array into the dot array. First argument can be a dot path, an array, or a function that returns an array. The second argument can be an array or a function, but should only be used if first argument is a key. Returns the dot instance

```
// Merge into whole data array
$dot->merge([
  'stats' => [
    'web' => [
      'hits' => 123,
      'leads' => 321
    ]
  ]
]);

$dot->get();

/* Returns:
Array
(
  [stats] => Array
    (
      [web] => Array
        (
          [hits] => 123
          [last_updated] => DateTime Object
            (
              [date] => 2017-07-25 13:34:49.000000
              [timezone_type] => 3
              [timezone] => America/Los_Angeles
            )

          [allow_tracking] => 1
          [leads] => 321
        )

      [mobile] => Array
        (
        )

    )
)
*/

// Merge array into a dot path
$dot->merge('stats.mobile', [
  'issues' => 33
]);

// Merge using function
$dot->merge('stats.mobile', function ($mobile) {
  return ['updated' => new DateTime];
});

// Merge into whole data array with function
$dot->merge(function ($data) {
  return ['new' => 123];
});
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2995d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/98d7b54497c660d47a640678bd4ba0b3ff2baa14fbefef0d57d6f6dd57d52d59?d=identicon)[jbizzay](/maintainers/jbizzay)

---

Top Contributors

[![jkuchynka](https://avatars.githubusercontent.com/u/238506?v=4)](https://github.com/jkuchynka "jkuchynka (7 commits)")

---

Tags

arrayphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[openlss/lib-array2xml

Array2XML conversion library credit to lalit.org

31053.8M51](/packages/openlss-lib-array2xml)[flarum/extension-manager

An extension manager to install, update and remove extension packages from the interface (Wrapper around composer).

11223.6k](/packages/flarum-extension-manager)[oat-sa/tao-community

TAO is an Open Source e-Testing platform that empowers you to build, deliver, and share innovative and engaging assessments online – in any language or subject matter.

105.3k1](/packages/oat-sa-tao-community)

PHPackages © 2026

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