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 $key[, string $separator = '.' ][, bool|null $isArray = null ]) : array<string|int, mixed>|object
This utility supports:
- 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
-
The key path to delete (e.g. "foo.bar" or "foo." or "").
- $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.
Tags
Return values
array<string|int, mixed>|object —The updated document after deletion.