A filtering implementation for verifying correct data and performing typical modifications to arrays
Requires PHP 7.0 or newer and uses composer to install further PHP dependencies. See the composer specification for more details.
filter-arrays-php can be installed for use in your project using composer.
The recommended way of using this library in your project is to add a composer.json
file to your project. The following contents would add filter-arrays-php as a dependency:
composer require traderinteractive/filter-arrays
This filter is a wrapper around in_array
including support for strict equality testing.
The following does a strict check for $value
against the 3 accepted values.
\TraderInteractive\Filter\Arrays::in($value, ['a', 'b', 'c']);
This filter verifies that the argument is an array and checks the length of the array against bounds. The default bounds are 1+, so an empty array fails by default.
The following checks that the $value
is an array with exactly 3 elements.
\TraderInteractive\Filter\Arrays::filter($value, 3, 3);
This filter flattens a multi-dimensional array to a single dimension. The order of values will be maintained, but the keys themselves will not. For example:
$value = \TraderInteractive\Filter\Arrays::flatten([[1, 2], [3, [4, 5]]]);
assert($value === [1, 2, 3, 4, 5]);
With a checkout of the code get Composer in your PATH and run: ``sh composer install ./vendor/bin/phpunit ./vendor/bin/phpcs
For more information on our build process, read through out our [Contribution Guidelines](./.github/CONTRIBUTING.md).