Key(mixed $key)
Key(mixed $key, Validatable $rule)
Key(mixed $key, Validatable $rule, bool $mandatory)
Validates an array key.
$dict = [
'foo' => 'bar'
];
v::key('foo')->isValid($dict); // true
You can also validate the key value itself:
v::key('foo', v::equals('bar'))->isValid($dict); // true
Third parameter makes the key presence optional:
v::key('lorem', v::stringType(), false)->isValid($dict); // true
The name of this validator is automatically set to the key name.
- Arrays
- Nesting
- Structures
Version | Description |
---|---|
0.3.9 | Created |
See also: