PHPackages                             mschindler83/array-access - 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. mschindler83/array-access

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

mschindler83/array-access
=========================

Easy array access

v1.5.1(4y ago)22.7k↑450%1MITPHPPHP &gt;=7.4

Since Feb 15Pushed 4y ago2 watchersCompare

[ Source](https://github.com/mschindler83/array-access)[ Packagist](https://packagist.org/packages/mschindler83/array-access)[ Docs](http://www.markus-schindler.de)[ RSS](/packages/mschindler83-array-access/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (1)

Array Access
============

[](#array-access)

[![Build Status](https://camo.githubusercontent.com/c2aad3b48fae3993685f405f8f5cfc216dc855f0c6eb6155af9be870f07ffced/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d736368696e646c657238332f61727261792d6163636573732f6d61737465722e737667)](https://travis-ci.org/mschindler83/array-access)[![Latest Stable Version](https://camo.githubusercontent.com/4f5b0ad4d93aa55f59c20e4e0b45de6eec4d213d8ddc9f82d64ff8602e742be6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d736368696e646c657238332f61727261792d6163636573732e737667)](https://packagist.org/packages/mschindler83/array-access)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/69b9f3520e44cc43b8c79d7015032e1c505db35ba6e0359841cd4e3e527c7205/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d736368696e646c657238332f61727261792d6163636573732e737667)](https://scrutinizer-ci.com/g/mschindler83/array-access/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/881e7b67d3b021b0e2c63cf430f252200d46c357027ceb0e04e12420d6c2504d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d736368696e646c657238332f61727261792d6163636573732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mschindler83/array-access/?branch=master)[![Code Intelligence Status](https://camo.githubusercontent.com/5669542670d179d47dd4c66b410752651a7f39e72fda6bd862fb21c45e0276dd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d736368696e646c657238332f61727261792d6163636573732f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![Monthly Downloads](https://camo.githubusercontent.com/76469322de7de461d16fcc386d1dd46bac344734dd9073e38fe823c42ed4fba0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d736368696e646c657238332f61727261792d6163636573732e737667)](https://packagist.org/packages/mschindler83/array-access)

Library to ease array access handling. Requires PHP &gt;= 7.4

Install
-------

[](#install)

`composer require mschindler83/array-access`

Features
--------

[](#features)

- Savely access typed values from a given array
- Optional JSON schema validation
- Support for datetime parsing
- Define your own validation callback when retrieving values
- Create a new array in form of "dot annotations"
- Easily write values to a specific path of the array

Usage Examples
--------------

[](#usage-examples)

### Creating access objects

[](#creating-access-objects)

#### Create access object from an array and access values

[](#create-access-object-from-an-array-and-access-values)

```
$array = [
    'key1' => [
        'key2' => [
            'key3' => 'the-value'
        ],
    ],
];

$access = ArrayAccess::create($array);

try {
    // Get the string value at the given path
    $value = $access->string('key1', 'key2', 'key3');

    // This will fail with an exception because we try to get an integer at the given path
    $invalidValue = $access->int('key1', 'key2', 'key3');
} catch (ArrayAccessFailed $e) {
    // handle errors
    echo $e->getMessage();
}

```

#### Create an array from "dot annotation"

[](#create-an-array-from-dot-annotation)

```
$access = ArrayAccess::newFromDotAnnotation(
    SimpleDotAnnotation::create('key1.key2.2.key3', 'the-value-1'),
    SimpleDotAnnotation::create('key1.key2.2.key4', 'the-value-2')
);

$plainArray = $access->data();

```

Plain array will contain:

```
Array
(
  [key1] => Array
    (
      [key2] => Array
        (
          [2] => Array
            (
              [key3] => the-value-1
              [key4] => the-value-2
            )
        )
    )
)

```

### Array access with JSON schema validation

[](#array-access-with-json-schema-validation)

```
$data = [
    'key1' => 'value1',
    'key2' => true,
];

$access = ArrayAccess::createWithJsonSchemaValidation($data, \file_get_contents('json-schema.json'));

```

JSON schema: &lt;json-schema.json&gt;

```
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "key1": {
      "type": "string",
      "minLength": 3,
      "maxLength": 64,
      "pattern": "^[a-zA-Z0-9\\-]+(\\s[a-zA-Z0-9\\-]+)*$"
    },
    "key2": {
      "type": "boolean"
    }
  },
  "required": ["key1", "key2"],
  "additionalProperties": false
}

```

If validation fails, an `ArrayAccessValidationFailed` exception will be thrown. You can get an `ArrayAccess` object of validation errors by calling the method `errorMapping()` on the exception.

### Access values

[](#access-values)

```
$array = [
    'root' => [
        'string-value' => 'the-value',
        'int-value' => 10,
        'float-value' => 9.99,
        'bool-value' => true,
        'array-value' => [1, 2, 3],
        'datetime-value' => '2020-01-01 12:00:00',
        'object-value' => new \stdClass(),
        'custom' => 'Choice 1',
    ],
];

// Create the access object
$access = ArrayAccess::create($array);

// This will return the string "the-value"
$access->string('root', 'string-value');

// This will return the integer "10"
$access->int('root', 'int-value');

// This will return the float "9.99"
$access->float('root', 'float-value');

// This will return the bool "true"
$access->bool('root', 'bool-value');

// This will return the array "[1, 2, 3]"
$access->array('root', 'array-value');

// This will return a new ArrayAccess object
$access->arrayAccess('root', 'array-value');

// This will return a \DateTimeImmutable object
$access->dateTimeImmutable('Y-m-d H:i:s', 'root', 'datetime-value');

// This will return a \DateTime object
$access->dateTime('Y-m-d H:i:s', 'root', 'datetime-value');

// This will return the \stdClass object
$access->objectOfType(\stdClass::class, 'root', 'object-value');

// This will return a mixed, depending on the array content, but only if the custom validation passes
// In this case it will return the string "Choice 1"
$access->callback(
    function ($value) {
        return in_array($value, ['Choice 1', 'Choice 2', 'Choice 3']);
    },
    'root', 'custom'
);

```

### Write to a path

[](#write-to-a-path)

```
$access = ArrayAccess::create([]);
$access->writeAtPath('the-value', 'at', 'some', 'path');
$theValue = $access->string('at', 'some', 'path');

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% 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 ~105 days

Recently: every ~132 days

Total

6

Last Release

1756d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4042f66ed6bd2585a8f7dc0e2a0fe78a78660ea4f5b4d5ced8663272d8b0bd71?d=identicon)[mschindler83](/maintainers/mschindler83)

---

Top Contributors

[![mschindler83](https://avatars.githubusercontent.com/u/2979969?v=4)](https://github.com/mschindler83 "mschindler83 (16 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")

---

Tags

arrayarray-helperarray-manipulationsphp74

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mschindler83-array-access/health.svg)

```
[![Health](https://phpackages.com/badges/mschindler83-array-access/health.svg)](https://phpackages.com/packages/mschindler83-array-access)
```

###  Alternatives

[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.4k423.9k30](/packages/mcp-sdk)[ramsey/conventional-commits

A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook action!

1931.2M122](/packages/ramsey-conventional-commits)[php-coord/php-coord

PHPCoord is a PHP library to aid in handling coordinates. It can convert coordinates for a point from one system to another and also calculate distance between points.

110914.5k12](/packages/php-coord-php-coord)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

96374.6k23](/packages/friendsoftypo3-content-blocks)[shel/neos-hyphens

A plugin for Neos CMS which provides hyphens for the inline editor

20200.7k1](/packages/shel-neos-hyphens)

PHPackages © 2026

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