respect-validation/docs/Key.md
Henrique Moody 66027b85a5 Documentation improvements
- Add a space after comments with `//`;
- Add missing "See also" sections in some files
2015-10-19 22:55:05 -02:00

34 lines
602 B
Markdown

# Key
- `v::key(string $name)`
- `v::key(string $name, v $validator)`
- `v::key(string $name, v $validator, boolean $mandatory = true)`
Validates an array key.
```php
$dict = [
'foo' => 'bar'
];
v::key('foo')->validate($dict); // true
```
You can also validate the key value itself:
```php
v::key('foo', v::equals('bar'))->validate($dict); // true
```
Third parameter makes the key presence optional:
```php
v::key('lorem', v::stringType(), false)->validate($dict); // true
```
The name of this validator is automatically set to the key name.
***
See also:
* [Attribute](Attribute.md)