agallou/array-filter-path

Recursively filter an array uning some json-y syntax

Maintainers

👁 agallou

Package info

github.com/agallou/ArrayFilterPath

pkg:composer/agallou/array-filter-path

Statistics

Installs: 21 856

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.1 2015-11-19 23:36 UTC

Requires

None

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 847a0f527a0ced57c5fa232f1c2b1d1e3991ebb0

  • Adrien Gallou <adriengallou.woop@gmail.com>

This package is auto-updated.

Last update: 2026-06-29 00:46:19 UTC


README

Example

Take for example this array :

$baseArray = array(
 'director' => array(
 'first_name' => 'Robert',
 'last_name' => 'Zemeckis',
 ),
 'actors' => array(
 array(
 'first_name' => 'Michael J.',
 'last_name' => 'Fox',
 ),
 array(
 'first_name' => 'Christopher',
 'last_name' => 'Lloyd',
 ),
 ),
 'label' => 'Back to the Future'
);

If we filter it like this :

use agallou\ArrayFilterPath\ArrayFilterPath as ArrayFilterPath;
$filter = new ArrayFilterPath();
$filters = array(
 'actors[].last_name',
 'label',
);
$filteredArray = $filter->filter($baseArray, $filters);

We will get an array like this, with only the actors last name and the label :

array(
 'actors' => array(
 array(
 'last_name' => 'Fox',
 ),
 array(
 'last_name' => 'Lloyd',
 ),
 ),
 'label' => 'Back to the Future'
);