PHP code example of fresh-advance / array-validator
1. Go to this page and download the library: Download fresh-advance/array-validator 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/ */
fresh-advance / array-validator example snippets
use Sieg\ArrayValidator\Keys;
use Sieg\ArrayValidator\Rule;
use Sieg\ArrayValidator\RuleCase;
use Sieg\ArrayValidator\RuleCaseCollection;
use Sieg\ArrayValidator\Validator;
$configurationExample = new RuleCaseCollection(
new RuleCase(
new Keys\All(),
new Rule\LengthRange(5, 7)
),
new RuleCase(
new Keys\Collection('field1', 'field3'),
new Rule\Expression('/value\d+/')
),
new RuleCase(
new Keys\Expression('/2$/'),
new Rule\Expression('/value\d+/'),
'Special message'
)
);
$dataExample = [
'field1' => 'value1',
'field2' => 'something'
];
$validator = new Validator($configurationExample);
$errors = $validator->validate($dataExample);
if (empty($errors)) {
// array fits validation configuration
echo 'ok';
} else {
print_r($errors);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.