Arrays
abstract class Arrays (View source)
Some array functions to help with common tasks
Methods
Explodes a $string delimited by $delimiter and passes each item in the array through intval().
Explodes a string and trims all values for whitespace in the ends.
Merges two arrays recursively and "binary safe" (integer keys are overridden as well), overruling similar values in the first array ($firstArray) with the values of the second array ($secondArray) in case of identical keys, ie. keeping the values of the second.
Merges two arrays recursively and "binary safe" (integer keys are overridden as well), overruling similar values in the first array ($firstArray) with the values of the second array ($secondArray) In case of identical keys, ie. keeping the values of the second. The given $toArray closure will be used if one of the two array keys contains an array and the other not. It should return an array.
Returns true if the given array contains elements of varying types
Replacement for array_reduce that allows any type for $initial (instead of only integer)
Returns the value of a nested array by following the specifed path.
Sets the given value in a nested array or object by following the specified path.
Unsets an element/part of a nested array by following the specified path.
Sorts multidimensional arrays by recursively calling ksort on its elements.
Recursively convert an object hierarchy into an associative array.
Recursively removes empty array elements.
Details
static array
integerExplode(string $delimiter, string $string)
Explodes a $string delimited by $delimiter and passes each item in the array through intval().
Corresponds to explode(), but with conversion to integers for all values.
static array
trimExplode(string $delimiter, string $string, bool $onlyNonEmptyValues = true)
Explodes a string and trims all values for whitespace in the ends.
If $onlyNonEmptyValues is set, then all blank ('') values are removed.
static array
arrayMergeRecursiveOverrule(array $firstArray, array $secondArray, bool $dontAddNewKeys = false, bool $emptyValuesOverride = true)
Merges two arrays recursively and "binary safe" (integer keys are overridden as well), overruling similar values in the first array ($firstArray) with the values of the second array ($secondArray) in case of identical keys, ie. keeping the values of the second.
static array
arrayMergeRecursiveOverruleWithCallback(array $firstArray, array $secondArray, Closure $toArray, Closure|null $overrideFirst = null)
Merges two arrays recursively and "binary safe" (integer keys are overridden as well), overruling similar values in the first array ($firstArray) with the values of the second array ($secondArray) In case of identical keys, ie. keeping the values of the second. The given $toArray closure will be used if one of the two array keys contains an array and the other not. It should return an array.
static bool
containsMultipleTypes(array $array)
Returns true if the given array contains elements of varying types
static mixed
array_reduce(array $array, string $function, mixed $initial = null)
Replacement for array_reduce that allows any type for $initial (instead of only integer)
static mixed
getValueByPath(array $array, array|string $path)
Returns the value of a nested array by following the specifed path.
static array|ArrayAccess
setValueByPath(array|ArrayAccess $subject, array|string $path, mixed $value)
Sets the given value in a nested array or object by following the specified path.
static array
unsetValueByPath(array $array, array|string $path)
Unsets an element/part of a nested array by following the specified path.
static bool
sortKeysRecursively(array $array, int $sortFlags = null)
Sorts multidimensional arrays by recursively calling ksort on its elements.
static array
convertObjectToArray(mixed $subject)
Recursively convert an object hierarchy into an associative array.
static array
removeEmptyElementsRecursively(array $array)
Recursively removes empty array elements.