deleteKeyValue.php
Table of Contents
Functions
- deleteKeyValue() : array<string|int, mixed>|object
- Deletes a value from an array or object using a dot-notated key path.
Functions
deleteKeyValue()
Deletes a value from an array or object using a dot-notated key path.
deleteKeyValue(array<string|int, mixed>|object $document, string|array<string|int, mixed> $key[, string $separator = '.' ][, bool|null $isArray = null ][, bool $strict = false ]) : array<string|int, mixed>|object
This utility supports:
- Single key deletion (string)
- Multiple key deletion (array of strings)
- Flat keys (e.g., "name")
- Nested keys (e.g., "user.profile.name")
- Wildcard deletion for sub-containers (e.g., "user.*")
- Global wildcard "*" to clear the entire document
The input can be an associative array or a stdClass-like object. Intermediate paths are ensured to exist before deletion.
Parameters
- $document : array<string|int, mixed>|object
-
The data source (array or object) to operate on.
- $key : string|array<string|int, mixed>
-
The key path(s) to delete (e.g. "foo.bar" or ["foo.bar", "baz.*"]).
- $separator : string = '.'
-
The separator used to split the key path. Defaults to '.'.
- $isArray : bool|null = null
-
Optional: force array (
true) or object (false) mode; ifnull, auto-detects. - $strict : bool = false
-
If true, throws exception when key doesn't exist. Default: false.
Tags
Return values
array<string|int, mixed>|object —The updated document after deletion.