KeyExists
KeyExists(int|string $key)
Validates if the given key exists in an array.
v::keyExists('name')->validate(['name' => 'The Respect Panda']); // true
v::keyExists('name')->validate(['email' => 'therespectpanda@gmail.com']); // false
v::keyExists(0)->validate(['a', 'b', 'c']); // true
v::keyExists(4)->validate(['a', 'b', 'c']); // false
v::keyExists('username')->validate(new ArrayObject(['username' => 'therespectpanda'])); // true
v::keyExists(5)->validate(new ArrayObject(['a', 'b', 'c'])); // false
Notes
- To validate an array against a given rule if the key exists, use KeyOptional instead.
- To validate an array against a given rule requiring the key to exist, use Key instead.
Categorization
- Arrays
- Structures
Changelog
Version | Description |
---|---|
3.0.0 | Created from Key |
See also: