class Arrays

Array tools library.

Methods

__construct()

Static class - cannot be instantiated.

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

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

static mixed
getRef($arr, $key)

Returns reference to array item.

static array
mergeTree($arr1, $arr2)

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

static int|false
searchKey($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.

Details

at line 22
final __construct()

Static class - cannot be instantiated.

at line 36
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 59
static mixed getRef($arr, $key)

Returns reference to array item.

Parameters

$arr
$key

Return Value

mixed

Exceptions

InvalidArgumentException

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

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

Parameters

$arr1
$arr2

Return Value

array

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

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

Parameters

$arr
$key

Return Value

int|false

offset if it is found, FALSE otherwise

at line 103
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 114
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 126
static void renameKey(array $arr, $oldKey, $newKey)

Renames key in array.

Parameters

array $arr
$oldKey
$newKey

Return Value

void

at line 141
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 151
static array flatten(array $arr, $preserveKeys = FALSE)

Returns flattened array.

Parameters

array $arr
$preserveKeys

Return Value

array

at line 166
static bool isList($value)

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

Parameters

$value

Return Value

bool

at line 176
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 228
static array normalize(array $arr, $filling = NULL)

Normalizes to associative array.

Parameters

array $arr
$filling

Return Value

array

at line 246
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