![]() |
VOOZH | about |
class Arrays
Array manipulation utilities.
Returns item from array. If it does not exist, it throws an exception, unless a default value is set.
Returns reference to array item. If the index does not exist, new one is created with value null.
Recursively merges two arrays. Useful for merging tree structures. Behaves like the + operator: key/value pairs from the second array are added to the first, with the first array's values taking precedence on key collisions. Nested arrays are merged recursively instead of replaced.
Returns zero-indexed position of given array key. Returns null if key is not found.
Tests an array for the presence of value.
No description
No description
No description
No description
Inserts the contents of the $inserted array into the $array immediately before the $key.
Inserts the contents of the $inserted array into the $array immediately after the $key.
Renames key in array.
Returns only those array items, which matches a regular expression $pattern.
Transforms multidimensional array to flat array.
Checks if the array is indexed in ascending order of numeric keys from zero, a.k.a list.
Transforms a flat array of rows into an associative tree using a path expression like 'field|field[]field->field=field'.
Converts array to associative: items with numeric keys are converted to keys, with $filling as their value.
Returns and removes the value of an item from an array. If it does not exist, it throws an exception, or returns $default, if provided.
No description
No description
No description
No description
No description
Invokes all callbacks and returns array of results.
Invokes method on every object in an array and returns array of results.
Copies the elements of the $array array to the $object object and then returns it.
Converts value to array key.
Returns a copy of $array where every item is cast to string and wrapped with $prefix and $suffix.
static mixed
get(array $array, string|int|array $key, mixed $default = null)
Returns item from array. If it does not exist, it throws an exception, unless a default value is set.
| array | $array |
| string|int|array | $key |
| mixed | $default |
| mixed |
| InvalidArgumentException |
static mixed
getRef(array $array, string|int|array $key)
Returns reference to array item. If the index does not exist, new one is created with value null.
| array | $array |
| string|int|array | $key |
| mixed |
| InvalidArgumentException |
static array
mergeTree(array $array1, array $array2)
Recursively merges two arrays. Useful for merging tree structures. Behaves like the + operator: key/value pairs from the second array are added to the first, with the first array's values taking precedence on key collisions. Nested arrays are merged recursively instead of replaced.
| array | $array1 |
| array | $array2 |
| array |
static int|null
getKeyOffset(array $array, string|int $key)
Returns zero-indexed position of given array key. Returns null if key is not found.
| array | $array |
| string|int | $key |
| int|null |
static int|null
searchKey(array $array, string|int $key)
deprecated
deprecated use getKeyOffset()
No description
| array | $array |
| string|int | $key |
| int|null |
static bool
contains(array $array, mixed $value)
Tests an array for the presence of value.
| array | $array |
| mixed | $value |
| bool |
static mixed
first(array $array, callable|null $predicate = null, callable|null $else = null)
No description
| array | $array |
| callable|null | $predicate |
| callable|null | $else |
| mixed |
static mixed
last(array $array, callable|null $predicate = null, callable|null $else = null)
No description
| array | $array |
| callable|null | $predicate |
| callable|null | $else |
| mixed |
static int|string|null
firstKey(array $array, callable|null $predicate = null)
No description
| array | $array |
| callable|null | $predicate |
| int|string|null |
static int|string|null
lastKey(array $array, callable|null $predicate = null)
No description
| array | $array |
| callable|null | $predicate |
| int|string|null |
static void
insertBefore(array $array, string|int|null $key, array $inserted)
Inserts the contents of the $inserted array into the $array immediately before the $key.
If $key is null (or does not exist), it is inserted at the beginning.
| array | $array |
| string|int|null | $key |
| array | $inserted |
| void |
static void
insertAfter(array $array, string|int|null $key, array $inserted)
Inserts the contents of the $inserted array into the $array immediately after the $key.
If $key is null (or does not exist), it is inserted at the end.
| array | $array |
| string|int|null | $key |
| array | $inserted |
| void |
static bool
renameKey(array $array, string|int $oldKey, string|int $newKey)
Renames key in array.
| array | $array |
| string|int | $oldKey |
| string|int | $newKey |
| bool |
static array
grep(array $array, string $pattern, bool|int $invert = false)
Returns only those array items, which matches a regular expression $pattern.
| array | $array |
| string | $pattern |
| bool|int | $invert |
| array |
static array
flatten(array $array, bool $preserveKeys = false)
Transforms multidimensional array to flat array.
| array | $array |
| bool | $preserveKeys |
| array |
static bool
isList(mixed $value)
Checks if the array is indexed in ascending order of numeric keys from zero, a.k.a list.
| mixed | $value |
| bool |
static array|stdClass
associate(array $array, string|array $path)
Transforms a flat array of rows into an associative tree using a path expression like 'field|field[]field->field=field'.
| array | $array |
| string|array | $path |
| array|stdClass |
static array
normalize(array $array, mixed $filling = null)
Converts array to associative: items with numeric keys are converted to keys, with $filling as their value.
| array | $array |
| mixed | $filling |
| array |
static mixed
pick(array $array, string|int $key, mixed $default = null)
Returns and removes the value of an item from an array. If it does not exist, it throws an exception, or returns $default, if provided.
| array | $array |
| string|int | $key |
| mixed | $default |
| mixed |
| InvalidArgumentException |
static bool
some(iterable $array, callable $predicate)
No description
| iterable | $array |
| callable | $predicate |
| bool |
static bool
every(iterable $array, callable $predicate)
No description
| iterable | $array |
| callable | $predicate |
| bool |
static array
filter(array $array, callable $predicate)
No description
| array | $array |
| callable | $predicate |
| array |
static array
map(iterable $array, callable $transformer)
No description
| iterable | $array |
| callable | $transformer |
| array |
static array
mapWithKeys(array $array, callable $transformer)
No description
| array | $array |
| callable | $transformer |
| array |
static array
invoke(iterable $callbacks, mixed ...$args)
Invokes all callbacks and returns array of results.
| iterable | $callbacks |
| mixed | ...$args |
| array |
static array
invokeMethod(iterable $objects, string $method, mixed ...$args)
Invokes method on every object in an array and returns array of results.
| iterable | $objects |
| string | $method |
| mixed | ...$args |
| array |
static object
toObject(iterable $array, object $object)
Copies the elements of the $array array to the $object object and then returns it.
| iterable | $array |
| object | $object |
| object |
static int|string
toKey(mixed $value)
Converts value to array key.
| mixed | $value |
| int|string |
static array
wrap(array $array, string $prefix = '', string $suffix = '')
Returns a copy of $array where every item is cast to string and wrapped with $prefix and $suffix.
| array | $array |
| string | $prefix |
| string | $suffix |
| array |
Prevents instantiation.