class Arrays

Array tools library.

Methods

static mixed
get(array $arr, $key, $default = null)

Returns item from array or $default if item is not set.

static mixed
getRef(array $arr, $key)

Returns reference to array item.

static array
mergeTree(array $arr1, array $arr2)

Recursively appends elements of remaining keys from the second array to the first.

static int|false
searchKey(array $arr, $key)

Searches the array for a given key and returns the offset if successful.

static void
insertBefore(array $arr, $key, array $inserted)

Inserts new array before item specified by key.

static void
insertAfter(array $arr, $key, array $inserted)

Inserts new array after item specified by key.

static void
renameKey(array $arr, $oldKey, $newKey)

Renames key in array.

static array
grep(array $arr, $pattern, $flags = 0)

Returns array entries that match the pattern.

static array
flatten(array $arr, $preserveKeys = false)

Returns flattened array.

static bool
isList($value)

Finds whether a variable is a zero-based integer indexed array.

static array|stdClass
associate(array $arr, $path)

Reformats table to associative tree. Path looks like 'field|field[]field->field=field'.

static array
normalize(array $arr, $filling = null)

Normalizes to associative array.

static mixed
pick(array $arr, $key, $default = null)

Picks element from the array by key and return its value.

static bool
some(array $arr, callable $callback)

Tests whether some element in the array passes the callback test.

static bool
every(array $arr, callable $callback)

Tests whether all elements in the array pass the callback test.

static array
map(array $arr, callable $callback)

Applies the callback to the elements of the array.

Details

at line 28
static mixed get(array $arr, $key, $default = null)

Returns item from array or $default if item is not set.

Parameters

array $arr
$key
$default

Return Value

mixed

Exceptions

InvalidArgumentException

at line 51
static mixed getRef(array $arr, $key)

Returns reference to array item.

Parameters

array $arr
$key

Return Value

mixed

Exceptions

InvalidArgumentException

at line 68
static array mergeTree(array $arr1, array $arr2)

Recursively appends elements of remaining keys from the second array to the first.

Parameters

array $arr1
array $arr2

Return Value

array

at line 84
static int|false searchKey(array $arr, $key)

Searches the array for a given key and returns the offset if successful.

Parameters

array $arr
$key

Return Value

int|false

offset if it is found, false otherwise

at line 95
static void insertBefore(array $arr, $key, array $inserted)

Inserts new array before item specified by key.

Parameters

array $arr
$key
array $inserted

Return Value

void

at line 106
static void insertAfter(array $arr, $key, array $inserted)

Inserts new array after item specified by key.

Parameters

array $arr
$key
array $inserted

Return Value

void

at line 118
static void renameKey(array $arr, $oldKey, $newKey)

Renames key in array.

Parameters

array $arr
$oldKey
$newKey

Return Value

void

at line 133
static array grep(array $arr, $pattern, $flags = 0)

Returns array entries that match the pattern.

Parameters

array $arr
$pattern
$flags

Return Value

array

at line 143
static array flatten(array $arr, $preserveKeys = false)

Returns flattened array.

Parameters

array $arr
$preserveKeys

Return Value

array

at line 158
static bool isList($value)

Finds whether a variable is a zero-based integer indexed array.

Parameters

$value

Return Value

bool

at line 168
static array|stdClass associate(array $arr, $path)

Reformats table to associative tree. Path looks like 'field|field[]field->field=field'.

Parameters

array $arr
$path

Return Value

array|stdClass

at line 223
static array normalize(array $arr, $filling = null)

Normalizes to associative array.

Parameters

array $arr
$filling

Return Value

array

at line 241
static mixed pick(array $arr, $key, $default = null)

Picks element from the array by key and return its value.

Parameters

array $arr
$key
$default

Return Value

mixed

Exceptions

InvalidArgumentException

at line 261
static bool some(array $arr, callable $callback)

Tests whether some element in the array passes the callback test.

Parameters

array $arr
callable $callback

Return Value

bool

at line 276
static bool every(array $arr, callable $callback)

Tests whether all elements in the array pass the callback test.

Parameters

array $arr
callable $callback

Return Value

bool

at line 291
static array map(array $arr, callable $callback)

Applies the callback to the elements of the array.

Parameters

array $arr
callable $callback

Return Value

array

Traits

Static class.