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:
- (bool) strict: Strict behavior for array search. Default false
- (bool) attachMissingKey: Attach value to the end of the array if the key does not exist. Default: true
- (int) offset: Add additional offset.
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>
-
Array the new entry should inserted to
- $keys : array<string|int, mixed>|string
-
The key or keys where the new entry should be added before
- $newKey : string
-
The key of the entry that should be added
- $newValue : mixed
-
The value of the entry that should be 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 in other cases