PHP code example of graze / array-filter

1. Go to this page and download the library: Download graze/array-filter 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/ */

    

graze / array-filter example snippets


$config = [
    'name ~' => '/test.*/i',
    'ctime >' => '{date:yesterday:U}',
    'status in' => [1, 2],
];
$input = [[
    'name' => 'test1234',
    'ctime' => 142353782,
    'status' => 2,
]];
$factory = new FilterFactory(new ValueFactory());
$filter = $factory->createFilters($config);
$filtered = array_filter($input, $filter);

$filter = new AllOfFilter();
$filter->addFilter(new ClosureFilter('name', v::regex('/test.*/i')))
       ->addFilter(v::key('ctime', v::date()->between('yesterday', 'today'))
       ->addFilter(function (array $data) {
           return isset($data['status']) && in_array($data['status'], [1, 2]);
       });

$filtered = array_filter($input, $filter);