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'.

Details

at line 24
final __construct()

Static class - cannot be instantiated.

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

Returns reference to array item.

Parameters

$arr
$key

Return Value

mixed

Exceptions

InvalidArgumentException

at line 78
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 94
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 105
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 116
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 128
static void renameKey(array $arr, $oldKey, $newKey)

Renames key in array.

Parameters

array $arr
$oldKey
$newKey

Return Value

void

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

Returns flattened array.

Parameters

array $arr
$preserveKeys

Return Value

array

at line 168
static bool isList($value)

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

Parameters

$value

Return Value

bool

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