agallou / array-filter-path
Recursively filter an array uning some json-y syntax
Installs: 18 323
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires (Dev)
- atoum/atoum: 2.3.0
- m6web/coke: 1.0.0
This package is auto-updated.
Last update: 2024-10-29 04:41:58 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' );