ArrayUtil
in package
Table of Contents
Methods
- insertAfterKey() : void
- Insert a value into an existing array by key name.
- insertBeforeKey() : mixed
- Insert a new entry before a specific or multiple keys in array.
- removeValue() : bool
- Removes a value in an array.
Methods
insertAfterKey()
Insert a value into an existing array by key name.
public
insertAfterKey(array<string|int, mixed> &$array, string $key, mixed $value[, string $newKey = null ][, array<string|int, mixed> $options = [] ]) : void
Additional options:
- (bool) strict: Strict behavior for array search. Default false
- (bool) attachIfKeyNotExist: Attach value at the end of the array if key not exist. Default: true
- (int) offset: Add an 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<string|int, mixed> = []
-
Additional options
insertBeforeKey()
Insert a new entry before a specific or multiple keys in array.
public
static insertBeforeKey(array<string|int, mixed> &$array, string|array<string|int, mixed> $keys, string $newKey, mixed $newValue) : mixed
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 : string|array<string|int, mixed>
-
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 in an array.
public
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