PHPackages                             danilopolani/laravel-array-destructuring - 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. danilopolani/laravel-array-destructuring

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

danilopolani/laravel-array-destructuring
========================================

Powerful array destructuring for Laravel

1.0.0(5y ago)258MITPHPPHP ^7.4|^8.0

Since Feb 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/danilopolani/laravel-array-destructuring)[ Packagist](https://packagist.org/packages/danilopolani/laravel-array-destructuring)[ Docs](https://github.com/danilopolani/laravel-array-destructuring)[ RSS](/packages/danilopolani-laravel-array-destructuring/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Laravel Array Destructuring
===========================

[](#laravel-array-destructuring)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f60cadf3b79747405771d7f1b9979be59c7663eea1e7e4dd797d3a180af5f8c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e696c6f706f6c616e692f6c61726176656c2d61727261792d64657374727563747572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danilopolani/laravel-array-destructuring)[![Build Status](https://camo.githubusercontent.com/c9d7b4e2b9ba55658d2cf520cbe6e6d89a7112630330ca0e35e7fb92b7e639b0/68747470733a2f2f7472617669732d63692e636f6d2f64616e696c6f706f6c616e692f6c61726176656c2d61727261792d64657374727563747572696e672e737667)](https://travis-ci.com/danilopolani/laravel-array-destructuring)

 [ ![](https://camo.githubusercontent.com/e721478c10904097f71b80b07f5b72bf247ed5370d62e46aa05c1f9f0acb1acc/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230417272617925323044657374727563747572696e672e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d64616e696c6f706f6c616e692532466c61726176656c2d61727261792d64657374727563747572696e67267061747465726e3d646f6d696e6f73267374796c653d7374796c655f31266465736372697074696f6e3d506f77657266756c2b61727261792b64657374727563747572696e672b666f722b4c61726176656c266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d646f74732d686f72697a6f6e74616c) ](https://github.com/danilopolani/laravel-array-destructuring)

Extend `Arr` support adding a `destructure` method to have a powerful array destruction in Laravel.

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
3. [Changelog](#changelog)
4. [Contributing](#contributing)
5. [Testing](#testing)
6. [Security](#security)
7. [Credits](#credits)
8. [License](#license)

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

[](#installation)

The package supports `Laravel 8.x` and `PHP >= 7.4`.

You can install the package via composer:

```
composer require danilopolani/laravel-array-destructuring
```

Thanks to the package auto-discovery feature, it will register itself automatically.

Usage
-----

[](#usage)

> **Note**: if a key is not found its value will be `null`. If all the elements inside a group of keys are not found, the returned value will be an empty array `[]`.

Basic destructuring for a key only

```
$post = [
	'title' => 'Article 1',
	'slug' => 'article-1',
	'description' => 'Lorem ipsum',
	'tags' => ['foo', 'bar'],
	'gallery' => [
	    ['image' => 'image.jpg'],
	    ['image' => 'image2.jpg'],
	],
];

[$tags, $article] = Arr::destructure($post, 'tags');

dump($tags); // ['foo', 'bar']
dump($article) // ['title' => 'Article 1', 'slug' => 'article-1', ...] without tags

[$notFoundKey, $article] = Arr::destructure($post, 'notFoundKey');

dump($notFoundKey); // null
```

Destructuring with multiple keys

```
$post = [
	'title' => 'Article 1',
	'slug' => 'article-1',
	'description' => 'Lorem ipsum',
	'tags' => ['foo', 'bar'],
	'gallery' => [
	    ['image' => 'image.jpg'],
	    ['image' => 'image2.jpg'],
	],
];

[$tags, $gallery, $article] = Arr::destructure($post, ['tags', 'gallery']);

dump($tags); // ['foo', 'bar']
dump($gallery); // [['image' => 'image.jpg'], ['image' => 'image2.jpg']]
dump($article) // ['title' => 'Article 1', 'slug' => 'article-1', 'description' => 'Lorem ipsum']
```

Destructuring with multiple grouped keys

```
$post = [
	'title' => 'Article 1',
	'slug' => 'article-1',
	'description' => 'Lorem ipsum',
	'tags' => ['foo', 'bar'],
	'gallery' => [
	    ['image' => 'image.jpg'],
	    ['image' => 'image2.jpg'],
	],
];

[$slug, $meta, $article] = Arr::destructure($post, ['slug', ['tags', 'gallery']]);

dump($slug); // article-1
dump($meta); // ['tags' => ['foo', 'bar'], 'gallery' => ['image' => 'image.jpg'], ['image' => 'image2.jpg']]
dump($article) // ['title' => 'Article 1', 'description' => 'Lorem ipsum']

[$notFoundGroup, $article] = Arr::destructure($post, [['notFound1', 'notFound2']]);

dump($notFoundGroup); // []
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Testing
-------

[](#testing)

Clone the repository and just run

```
composer test
```

With Docker (Windows):

```
docker run --rm -v %cd%:/app composer:latest bash -c "cd /app && composer install --ignore-platform-reqs && ./vendor/bin/phpunit"
```

With Docker (Linux/OSX):

```
docker run --rm -v $(pwd):/app composer:latest bash -c "cd /app && composer install && ./vendor/bin/phpunit"
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Danilo Polani](https://github.com/danilopolani)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

1908d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ed568a3c0ca4ca3d3b7d199371b455e3a50347dcffc39ec01c94e04743bdcd6?d=identicon)[Theraloss](/maintainers/Theraloss)

---

Top Contributors

[![danilopolani](https://avatars.githubusercontent.com/u/6277291?v=4)](https://github.com/danilopolani "danilopolani (2 commits)")

---

Tags

laraveltheralossarray destructuring

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/danilopolani-laravel-array-destructuring/health.svg)

```
[![Health](https://phpackages.com/badges/danilopolani-laravel-array-destructuring/health.svg)](https://phpackages.com/packages/danilopolani-laravel-array-destructuring)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[xefi/faker-php-laravel

Faker php integration with laravel

1915.1k](/packages/xefi-faker-php-laravel)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

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