PHPackages                             khalyomede/array-get - 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. khalyomede/array-get

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

khalyomede/array-get
====================

Function to traverse an array using dot and star syntax.

v0.1.2(7y ago)163[1 PRs](https://github.com/khalyomede/array-get/pulls)1MITPHPPHP &gt;=7.2.0

Since Nov 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/khalyomede/array-get)[ Packagist](https://packagist.org/packages/khalyomede/array-get)[ RSS](/packages/khalyomede-array-get/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (4)Used By (1)

array-get
=========

[](#array-get)

Function to traverse an array using dot and star syntax. Inspired by [Laravel](https://laravel.com) Validator class.

[![PHP from Packagist](https://camo.githubusercontent.com/95710987863c3ce7341b26582d6163d4374116580f03c17850e9450aee05e027/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f61727261792d6765742e737667)](https://camo.githubusercontent.com/95710987863c3ce7341b26582d6163d4374116580f03c17850e9450aee05e027/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f61727261792d6765742e737667) [![Packagist](https://camo.githubusercontent.com/9e0f1089ee2d2b43c665e3f47be671ff3e50f2fb3bb327372795f390819552e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f61727261792d6765742e737667)](https://camo.githubusercontent.com/9e0f1089ee2d2b43c665e3f47be671ff3e50f2fb3bb327372795f390819552e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f61727261792d6765742e737667) [![Codeship](https://camo.githubusercontent.com/056e89acdc16f7dcd3f7daa3ab95275af9cf9170c1a049694b5c6ca9fa4d53eb/68747470733a2f2f696d672e736869656c64732e696f2f636f6465736869702f34623039323862302d636331642d303133362d376539642d3765353734643566666236392e737667)](https://camo.githubusercontent.com/056e89acdc16f7dcd3f7daa3ab95275af9cf9170c1a049694b5c6ca9fa4d53eb/68747470733a2f2f696d672e736869656c64732e696f2f636f6465736869702f34623039323862302d636331642d303133362d376539642d3765353734643566666236392e737667) [![Packagist](https://camo.githubusercontent.com/090068a99f495804f583287fc8c88c50530b442a9634f69a9237faa7cd2e8c8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f61727261792d6765742e737667)](https://camo.githubusercontent.com/090068a99f495804f583287fc8c88c50530b442a9634f69a9237faa7cd2e8c8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f61727261792d6765742e737667)

```
$array = [
  'firstname' => 'John',
  'lastname' => 'Doe',
  'orders' => [
    [
      'id' => 36,
      'ordered_at' => '2018-11-16 22:12:38',
      'product' => [
        'id' => 11,
        'name' => 'Huawei P20'
      ]
    ],
    [
      'id' => 47,
      'ordered_at' => '2018-11-16 22:13:04',
      'product' => [
        'id' => 208,
        'name' => 'Powerbank Tesla'
      ]
    ]
  ]
];

var_dump( array_get($array, 'firstname') ); // "John"
var_dump( array_get($array, 'orders.1.ordered_at') ); // "2018-11-16 22:13:04"
var_dump( array_get($array, 'orders.*.product.name') ) // ["Huawei P20", "Powerbank Tesla"]
```

Summary
-------

[](#summary)

- [Installation](#installation)
- [Examples](#examples)

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

[](#installation)

In your project directory:

```
composer require khalyomede/array-get:0.*
```

Examples
--------

[](#examples)

- [Example 1: get a value from a key](#example-1-get-a-value-from-a-key)
- [Example 2: get a value from an indexed key](#example-2-get-a-value-from-an-indexed-key)
- [Example 3: get values from a nested key](#example-3-get-values-from-a-nested-key)
- [Example 4: use OOP style](#example-4-use-oop-style)
- [Example 5: get the key of each items](#example-5-get-the-key-of-each-items)

### Example 1: get a value from a key

[](#example-1-get-a-value-from-a-key)

```
require __DIR__ . '/../vendor/autoload.php';

use function Khalyomede\array_get;

$array = [
  'firstname' => 'John',
  'lastname' => 'Doe',
  'orders' => [
    [
      'id' => 36,
      'ordered_at' => '2018-11-16 22:12:38',
      'product' => [
        'id' => 11,
        'name' => 'Huawei P20'
      ]
    ],
    [
      'id' => 47,
      'ordered_at' => '2018-11-16 22:13:04',
      'product' => [
        'id' => 208,
        'name' => 'Powerbank Tesla'
      ]
    ]
  ]
];

$firstname = array_get($array, 'firstname');

var_dump($firstname); // "John"
```

### Example 2: get a value from an indexed key

[](#example-2-get-a-value-from-an-indexed-key)

```
require __DIR__ . '/../vendor/autoload.php';

use function Khalyomede\array_get;

$array = [
  'firstname' => 'John',
  'lastname' => 'Doe',
  'orders' => [
    [
      'id' => 36,
      'ordered_at' => '2018-11-16 22:12:38',
      'product' => [
        'id' => 11,
        'name' => 'Huawei P20'
      ]
    ],
    [
      'id' => 47,
      'ordered_at' => '2018-11-16 22:13:04',
      'product' => [
        'id' => 208,
        'name' => 'Powerbank Tesla'
      ]
    ]
  ]
];

$ordered_at = array_get($array, 'orders.1.ordered_at');

var_dump($ordered_at); // "2018-11-16 22:13:04"
```

### Example 3: get values from a nested key

[](#example-3-get-values-from-a-nested-key)

```
require __DIR__ . '/../vendor/autoload.php';

use function Khalyomede\array_get;

$array = [
  'firstname' => 'John',
  'lastname' => 'Doe',
  'orders' => [
    [
      'id' => 36,
      'ordered_at' => '2018-11-16 22:12:38',
      'product' => [
        'id' => 11,
        'name' => 'Huawei P20'
      ]
    ],
    [
      'id' => 47,
      'ordered_at' => '2018-11-16 22:13:04',
      'product' => [
        'id' => 208,
        'name' => 'Powerbank Tesla'
      ]
    ]
  ]
];

$ordered_at = array_get($array, 'orders.*.product.name');

var_dump($ordered_at); // ["Huawei P20", "Powerbank Tesla"]
```

### Example 4: use OOP style

[](#example-4-use-oop-style)

```
require __DIR__ . '/../vendor/autoload.php';

use Khalyomede\Arr;

$array = [
  'firstname' => 'John',
  'lastname' => 'Doe',
  'orders' => []
];

$firstname = (new Arr($array))->get('firstname');

var_dump($firstname); // "John"
```

### Example 5: get the key of each items

[](#example-5-get-the-key-of-each-items)

```
require __DIR__ . '/../vendor/autoload.php';

use function Khalyomede\array_get;

$tasks = [
    ['id' => 53, 'name' => 'read mails'],
    ['id' => 61, 'name' => 'factorize the code'],
    ['id' => 71, 'name' => 'learn ES8 & ES9']
];

var_dump( array_get($tasks, '*.name') ); // ["read mails", "factorize the code", "learn ES8 & ES9"]
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

Total

3

Last Release

2735d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Tags

arraydotfunctiongetstarsyntaxtraverse

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/khalyomede-array-get/health.svg)

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

###  Alternatives

[ip2location/ip2location-php

\[Official Release\] IP2Location PHP API to get location info from IPv4 and IPv6 address.

2133.9M33](/packages/ip2location-ip2location-php)[sylius-labs/polyfill-symfony-event-dispatcher

Symfony EventDispatcher Polyfill

218.2M2](/packages/sylius-labs-polyfill-symfony-event-dispatcher)[jolicode/php-os-helper

Helpers to detect the OS of the machine where PHP is running.

212.8M4](/packages/jolicode-php-os-helper)

PHPackages © 2026

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