PHPackages                             igorw/get-in - 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. igorw/get-in

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

igorw/get-in
============

Functions for hash map (assoc array) traversal.

v1.0.3(11y ago)40012.8M—8.9%23[3 PRs](https://github.com/igorw/get-in/pulls)20MITPHPPHP &gt;=5.4

Since Jan 8Pushed 5y ago8 watchersCompare

[ Source](https://github.com/igorw/get-in)[ Packagist](https://packagist.org/packages/igorw/get-in)[ RSS](/packages/igorw-get-in/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (20)

get-in
======

[](#get-in)

[![Build Status](https://camo.githubusercontent.com/000c357ab0e563a496618c92a34934c62b64505a9735ff18b1df1c024df8bc63/68747470733a2f2f7472617669732d63692e6f72672f69676f72772f6765742d696e2e706e67)](https://travis-ci.org/igorw/get-in)

Functions for hash map (assoc array) traversal.

When dealing with nested associative structures, traversing them can become quite a pain. Mostly because of the amount of `isset` checking that is necessary.

For example, to access a nested key `['foo']['bar']['baz']`, you must do something like this:

```
$baz = (isset($data['foo']['bar']['baz'])) ? $data['foo']['bar']['baz'] : null;
```

Enough already! `get-in` provides a better way:

```
$baz = igorw\get_in($data, ['foo', 'bar', 'baz']);
```

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

[](#installation)

Through [composer](http://getcomposer.org):

```
$ composer require igorw/get-in:~1.0
```

Usage
-----

[](#usage)

### get\_in

[](#get_in)

Retrieve value from a nested structure using a list of keys:

```
$users = [
    ['name' => 'Igor Wiedler'],
    ['name' => 'Jane Doe'],
    ['name' => 'Acme Inc'],
];

$name = igorw\get_in($users, [1, 'name']);
//= 'Jane Doe'
```

Non existent keys return null:

```
$data = ['foo' => 'bar'];

$baz = igorw\get_in($data, ['baz']);
//= null
```

You can provide a default value that will be used instead of null:

```
$data = ['foo' => 'bar'];

$baz = igorw\get_in($data, ['baz'], 'qux');
//= 'qux'
```

### update\_in

[](#update_in)

Apply a function to the value at a particular location in a nested structure:

```
$data = ['foo' => ['answer' => 42]];
$inc = function ($x) {
    return $x + 1;
};

$new = igorw\update_in($data, ['foo', 'answer'], $inc);
//= ['foo' => ['answer' => 43]]
```

You can variadically provide additional arguments for the function:

```
$data = ['foo' => 'bar'];
$concat = function (/* $args... */) {
    return implode('', func_get_args());
};

$new = igorw\update_in($data, ['foo'], $concat, ' is the ', 'best');
//= ['foo' => 'bar is the best']
```

### assoc\_in

[](#assoc_in)

Set a value at a particular location:

```
$data = ['foo' => 'bar'];

$new = igorw\assoc_in($data, ['foo'], 'baz');
//= ['foo' => 'baz']
```

It will also set the value if it does not exist yet:

```
$data = [];

$new = igorw\assoc_in($data, ['foo', 'bar'], 'baz');
//= ['foo' => ['bar' => 'baz']]
```

Inspiration
-----------

[](#inspiration)

The naming and implementation is inspired by the `get-in`, `update-in` and `assoc-in` functions from [clojure](http://clojure.org).

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity65

Solid adoption and visibility

Community35

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 64.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 ~113 days

Total

4

Last Release

4172d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3afcc18d00fff840775bbf9570b3e9cd3997ca4820b9bfb14caf6da3ae580370?d=identicon)[igorw](/maintainers/igorw)

---

Top Contributors

[![igorw](https://avatars.githubusercontent.com/u/88061?v=4)](https://github.com/igorw "igorw (24 commits)")[![marcioAlmada](https://avatars.githubusercontent.com/u/227395?v=4)](https://github.com/marcioAlmada "marcioAlmada (2 commits)")[![AnhNhan](https://avatars.githubusercontent.com/u/3199392?v=4)](https://github.com/AnhNhan "AnhNhan (2 commits)")[![mhor](https://avatars.githubusercontent.com/u/4103719?v=4)](https://github.com/mhor "mhor (1 commits)")[![pablodip](https://avatars.githubusercontent.com/u/98504?v=4)](https://github.com/pablodip "pablodip (1 commits)")[![peterjmag](https://avatars.githubusercontent.com/u/352105?v=4)](https://github.com/peterjmag "peterjmag (1 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (1 commits)")[![toin0u](https://avatars.githubusercontent.com/u/672421?v=4)](https://github.com/toin0u "toin0u (1 commits)")[![whatthejeff](https://avatars.githubusercontent.com/u/306525?v=4)](https://github.com/whatthejeff "whatthejeff (1 commits)")[![wouterj](https://avatars.githubusercontent.com/u/749025?v=4)](https://github.com/wouterj "wouterj (1 commits)")[![gpg0](https://avatars.githubusercontent.com/u/449748?v=4)](https://github.com/gpg0 "gpg0 (1 commits)")[![h4cc](https://avatars.githubusercontent.com/u/2981491?v=4)](https://github.com/h4cc "h4cc (1 commits)")

---

Tags

hash-mapassoc-array

### Embed Badge

![Health badge](/badges/igorw-get-in/health.svg)

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

###  Alternatives

[equip/structure

Simple, immutable data structures

40201.9k2](/packages/equip-structure)

PHPackages © 2026

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