hasKeyValue.php
Table of Contents
Functions
- hasKeyValue() : bool
- Checks whether a given key or property exists in an array or object, including nested paths.
Functions
hasKeyValue()
Checks whether a given key or property exists in an array or object, including nested paths.
hasKeyValue(array<string|int, mixed>|object $document, string $key[, string $separator = '.' ][, bool|null $isArray = null ]) : bool
This helper determines if the specified key exists in the given document (array or object). It supports nested access via a separator (default is '.') and can optionally force the document type (array or object).
If any part of the path does not exist, false
is returned. This function does not rely on
__get()
or __isset()
magic methods for objects.
Parameters
- $document : array<string|int, mixed>|object
-
The document (array or object) to inspect.
- $key : string
-
The key or property path to check. Supports nesting with separator.
- $separator : string = '.'
-
Separator used for nested paths. Default is '.'.
- $isArray : bool|null = null
-
Optional: true if document is an array, false if object, null to auto-detect.
Tags
Return values
bool —True if the full key path exists, false otherwise.