PHPackages                             jdz/data - 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. jdz/data

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

jdz/data
========

Data utility class for nested array manipulation

2.0.1(2mo ago)0685MITPHPPHP &gt;=8.0

Since Dec 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/joffreydemetz/data)[ Packagist](https://packagist.org/packages/jdz/data)[ Docs](https://jdz.joffreydemetz.com/data/)[ RSS](/packages/jdz-data/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (5)

JDZ Data
========

[](#jdz-data)

A PHP utility class for manipulating nested arrays using dot notation.

Features
--------

[](#features)

- 🎯 **Dot Notation**: Access nested array values with simple dot notation (`user.profile.name`)
- 🔢 **Numeric Keys**: Work seamlessly with array indices
- 🔄 **Bulk Operations**: Set multiple values at once with merge support
- 🎨 **Typed Getters**: Type-safe retrieval with `getBool()`, `getInt()`, `getArray()`
- 🔗 **Method Chaining**: Fluent interface for elegant code
- 🎭 **Null Handling**: Optional null value preservation
- ✅ **Type Safe**: Full PHP 8.0+ type declarations

Installation
------------

[](#installation)

```
composer require jdz/data
```

Requirements
------------

[](#requirements)

- PHP 8.0 or higher

Quick Start
-----------

[](#quick-start)

```
use JDZ\Utils\Data;

$data = new Data();

// Set values using dot notation
$data->set('user.name', 'John Doe');
$data->set('user.email', 'john@example.com');
$data->set('user.settings.theme', 'dark');

// Get values
echo $data->get('user.name'); // "John Doe"
echo $data->get('user.age', 30); // 30 (default value)

// Check existence
if ($data->has('user.email')) {
    echo "Email exists!";
}

// Work with arrays
$data->set('users.0.name', 'John');
$data->set('users.1.name', 'Jane');

// Get typed values
$isActive = $data->getBool('user.active', true);
$count = $data->getInt('user.login_count', 0);
$tags = $data->getArray('user.tags', []);
```

Documentation
-------------

[](#documentation)

### Setting Values

[](#setting-values)

#### `set(string $path, mixed $value): self`

[](#setstring-path-mixed-value-self)

Set a single value using dot notation.

```
$data->set('app.name', 'MyApp');
$data->set('app.version', '1.0.0');
$data->set('config.database.host', 'localhost');
```

#### `sets(array $data, bool $merge = true): self`

[](#setsarray-data-bool-merge--true-self)

Set multiple values at once.

```
// Merge with existing data
$data->sets([
    'api.endpoint' => 'https://api.example.com',
    'api.timeout' => 30,
], true);

// Set without merging
$data->sets([
    'config.debug' => true,
], false);
```

### Getting Values

[](#getting-values)

#### `get(string $path, mixed $default = null): mixed`

[](#getstring-path-mixed-default--null-mixed)

Get a value with an optional default.

```
$name = $data->get('user.name');
$country = $data->get('user.country', 'USA');
```

#### `getBool(string $path, bool $default = false): bool`

[](#getboolstring-path-bool-default--false-bool)

Get a boolean value. Converts `1`, `'1'`, and `true` to `true`.

```
$isEnabled = $data->getBool('features.api');
$hasAccess = $data->getBool('user.premium', false);
```

#### `getInt(string $path, int $default = 0): int`

[](#getintstring-path-int-default--0-int)

Get an integer value with automatic type conversion.

```
$timeout = $data->getInt('config.timeout');
$retries = $data->getInt('config.retries', 3);
```

#### `getArray(string $path, array $default = []): array`

[](#getarraystring-path-array-default---array)

Get an array value. Non-array values are cast to arrays.

```
$tags = $data->getArray('post.tags');
$items = $data->getArray('list.items', ['default']);
```

### Checking and Removing

[](#checking-and-removing)

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

[](#hasstring-path-bool)

Check if a key exists.

```
if ($data->has('user.email')) {
    // Email is set
}
```

#### `erase(string $path): self`

[](#erasestring-path-self)

Remove a value.

```
$data->erase('user.temporary_token');
$data->erase('cache.expired');
```

#### `def(string $path, mixed $default = ''): self`

[](#defstring-path-mixed-default---self)

Set a value only if it doesn't already exist.

```
$data->def('config.timeout', 30); // Sets if not exists
$data->def('config.retries', 3);  // Sets if not exists
```

### Utility Methods

[](#utility-methods)

#### `all(): array`

[](#all-array)

Get all data as an array.

```
$allData = $data->all();
```

#### `preserveNulls(bool $preserve = true): self`

[](#preservenullsbool-preserve--true-self)

Enable or disable null value preservation.

```
$data->preserveNulls(true);
$data->set('user.optional', null); // Null is preserved
```

Working with Arrays
-------------------

[](#working-with-arrays)

Access array elements using numeric keys:

```
$data->set('items.0', 'First');
$data->set('items.1', 'Second');
$data->set('items.2', 'Third');

echo $data->get('items.0'); // "First"
```

Build complex structures:

```
$data->set('users.0.name', 'John');
$data->set('users.0.email', 'john@example.com');
$data->set('users.1.name', 'Jane');
$data->set('users.1.email', 'jane@example.com');

$users = $data->getArray('users');
// [
//   ['name' => 'John', 'email' => 'john@example.com'],
//   ['name' => 'Jane', 'email' => 'jane@example.com']
// ]
```

Method Chaining
---------------

[](#method-chaining)

All mutating methods return `$this` for fluent chaining:

```
$config = (new Data())
    ->set('app.name', 'MyApp')
    ->set('app.version', '1.0.0')
    ->def('app.debug', false)
    ->def('app.timeout', 30)
    ->erase('app.temporary');
```

Examples
--------

[](#examples)

See the [examples](examples/) directory for detailed examples:

- `01-basic-usage.php` - Basic operations
- `02-typed-getters.php` - Typed getter methods
- `03-array-keys.php` - Working with arrays
- `04-bulk-operations.php` - Bulk setting operations
- `05-erase-and-def.php` - Removing and defaulting values
- `06-null-handling.php` - Null value handling
- `07-method-chaining.php` - Method chaining examples

Run example:

```
php examples/01-basic-usage.php
```

Testing
-------

[](#testing)

Run all tests:

```
composer test
# or
vendor/bin/phpunit
```

Run tests with coverage report (HTML):

```
composer test-coverage
# Coverage report will be generated in the coverage/ directory
```

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance83

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

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

Every ~43 days

Recently: every ~87 days

Total

11

Last Release

87d ago

Major Versions

1.0.8 → 2.0.02025-12-03

PHP version history (2 changes)1.0.3PHP &gt;=8.1

2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e83e3701566e43438525ed14578487e732b849d152b5071aa1613a0dad96913?d=identicon)[jdz](/maintainers/jdz)

---

Top Contributors

[![joffreydemetz](https://avatars.githubusercontent.com/u/15113527?v=4)](https://github.com/joffreydemetz "joffreydemetz (24 commits)")

---

Tags

configutilitiesdatasetJDZ

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jdz-data/health.svg)

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k493.9M1.6k](/packages/symfony-options-resolver)[league/config

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

564302.2M24](/packages/league-config)

PHPackages © 2026

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