Array Filtering
Via Composer
$ composer require graze/array-filter
There is a factory which takes in a set of string definitions and creates filters based on each one
$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);
$ make
$ make test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.