PHP code example of agallou / array-filter-path

1. Go to this page and download the library: Download agallou/array-filter-path library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

agallou / array-filter-path example snippets


$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'
);

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

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