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), supporting nested keys using a separator (default is '.').
Unlike isset(), this function considers keys with null values as existing.
That means a key exists if it is present in the array/object, even if its value is null.
It can optionally force the document type (array or object) via the $isArray parameter.
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.