StaticArrayUtil
extends AbstractStaticUtil
in package
Table of Contents
Methods
- insertAfterKey() : void
- Insert a value into an existing array by key name.
- insertBeforeKey() : void
- Insert a new entry before a specific or multiple keys in array.
- removeValue() : bool
- Removes a value from an array.
Methods
insertAfterKey()
Insert a value into an existing array by key name.
public
static insertAfterKey(array<string|int, mixed> &$array, string $key, mixed $value[, string $newKey = null ][, array{strict?: bool, attachMissingKey?: bool, offset?: int} $options = [] ]) : void
Additional options:
- strict (bool): Strict behavior for array search. (default: false)
- attachMissingKey (bool): Attach value to the end of the array if the key does not exist. (default: true)
- offset (int): Add additional offset. (default: 0)
Parameters
- $array : array<string|int, mixed>
-
The target array
- $key : string
-
the existing target key in the array
- $value : mixed
-
the new value to be inserted
- $newKey : string = null
- $options : array{strict?: bool, attachMissingKey?: bool, offset?: int} = []
-
Additional options
insertBeforeKey()
Insert a new entry before a specific or multiple keys in array.
public
static insertBeforeKey(array<string|int, mixed> &$array, array<string|int, mixed>|string $keys, string $newKey, mixed $newValue) : void
If the keys not exist, the new entry is added to the end of the array. Array is passed as reference.
Parameters
- $array : array<string|int, mixed>
-
The Array to modify
- $keys : array<string|int, mixed>|string
-
The key or keys before which the new entry should be added
- $newKey : string
-
The key of the entry added
- $newValue : mixed
-
The value of the entry added
removeValue()
Removes a value from an array.
public
static removeValue(mixed $value, array<string|int, mixed> &$array) : bool
Parameters
- $value : mixed
- $array : array<string|int, mixed>
Return values
bool —Returns true if the value has been found and removed, false otherwise.