class ArrayLib (View source)

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib

Library of static methods for manipulating arrays.

Methods

public
__construct()

No description

public static 
array
invert(array $arr) deprecated

Inverses the first and second level keys of an associative array, keying the result by the second level, and combines all first level entries within them.

public static 
array
valuekey($arr) deprecated

Return an array where the keys are all equal to the values.

public static 
array
array_values_recursive(array $array) deprecated

Flattens a multi-dimensional array to a one level array without preserving the keys

public static 
array
filter_keys($arr, $keys) deprecated

Filter an array by keys (useful for only allowing certain form-input to be saved).

public static 
bool
is_associative(array $array) deprecated

Determines if an array is associative by checking for existing keys via array_key_exists().

public static 
bool
in_array_recursive(mixed $needle, array $haystack, bool $strict = false) deprecated

Recursively searches an array $haystack for the value(s) $needle.

public static 
array
array_map_recursive($f, $array) deprecated

Similar to array_map, but recurses when arrays are encountered.

public static 
array
array_merge_recursive(array $array) deprecated

Recursively merges two or more arrays.

public static 
array
flatten(array $array, bool $preserveKeys = true, array $out = []) deprecated

Takes an multi dimension array and returns the flattened version.

public static 
iterateVolatile(array $list) deprecated

Iterate list, but allowing for modifications to the underlying list.

public static 
void
shuffleAssociative(array $array) deprecated

Similar to shuffle, but retains the existing association between the keys and the values.

public static 
array
insertBefore(array $array, mixed $insert, mixed $before, bool $strict = false, bool $splatInsertArray = false)

Insert a value into an array before another given value.

public static 
array
insertAfter(array $array, mixed $insert, mixed $after, bool $strict = false, bool $splatInsertArray = false)

Insert a value into an array after another given value.

Details

__construct()

No description

static array invert(array $arr) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::invert()

Inverses the first and second level keys of an associative array, keying the result by the second level, and combines all first level entries within them.

Before:

array( 'row1' => array( 'col1' =>'val1', 'col2' => 'val2' ), 'row2' => array( 'col1' => 'val3', 'col2' => 'val4' ) )

After:

array( 'col1' => array( 'row1' => 'val1', 'row2' => 'val3', ), 'col2' => array( 'row1' => 'val2', 'row2' => 'val4', ), )

Parameters

array $arr

Return Value

array

static array valuekey($arr) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::valuekey()

Return an array where the keys are all equal to the values.

Parameters

$arr array

Return Value

array

static array array_values_recursive(array $array) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_values_recursive()

Flattens a multi-dimensional array to a one level array without preserving the keys

Parameters

array $array

Return Value

array

static array filter_keys($arr, $keys) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::filter_keys()

Filter an array by keys (useful for only allowing certain form-input to be saved).

Parameters

$arr array
$keys array

Return Value

array

static bool is_associative(array $array) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::is_associative()

Determines if an array is associative by checking for existing keys via array_key_exists().

Parameters

array $array

Return Value

bool

See also

http://nz.php.net/manual/en/function.is-array.php#121692

static bool in_array_recursive(mixed $needle, array $haystack, bool $strict = false) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive()

Recursively searches an array $haystack for the value(s) $needle.

Assumes that all values in $needle (if $needle is an array) are at the SAME level, not spread across multiple dimensions of the $haystack.

Parameters

mixed $needle
array $haystack
bool $strict

Return Value

bool

static array array_map_recursive($f, $array) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_map_recursive()

Similar to array_map, but recurses when arrays are encountered.

Actually only one array argument is supported.

Parameters

$f

callback to apply

$array array

Return Value

array

static array array_merge_recursive(array $array) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive()

Recursively merges two or more arrays.

Behaves similar to array_merge_recursive(), however it only merges values when both are arrays rather than creating a new array with both values, as the PHP version does. The same behaviour also occurs with numeric keys, to match that of what PHP does to generate $_REQUEST.

Parameters

array $array

Return Value

array

static array flatten(array $array, bool $preserveKeys = true, array $out = []) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::flatten()

Takes an multi dimension array and returns the flattened version.

Parameters

array $array
bool $preserveKeys
array $out

Return Value

array

static Generator iterateVolatile(array $list) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile()

Iterate list, but allowing for modifications to the underlying list.

Items in $list will only be iterated exactly once for each key, and supports items being removed or deleted. List must be associative.

Parameters

array $list

Return Value

Generator

static void shuffleAssociative(array $array) deprecated

deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::shuffleAssociative()

Similar to shuffle, but retains the existing association between the keys and the values.

Shuffles the array in place.

Parameters

array $array

Return Value

void

static array insertBefore(array $array, mixed $insert, mixed $before, bool $strict = false, bool $splatInsertArray = false)

Insert a value into an array before another given value.

Does not preserve keys.

Parameters

array $array
mixed $insert
mixed $before

The value to check for. If this value isn't in the source array, $insert will be put at the end.

bool $strict

If true then this will perform a strict type comparison to look for the $before value in the source array.

bool $splatInsertArray

If true, $insert must be an array. Its values will be splatted into the source array.

Return Value

array

static array insertAfter(array $array, mixed $insert, mixed $after, bool $strict = false, bool $splatInsertArray = false)

Insert a value into an array after another given value.

Does not preserve keys.

Parameters

array $array
mixed $insert
mixed $after

The value to check for. If this value isn't in the source array, $insert will be put at the end.

bool $strict

If true then this will perform a strict type comparison to look for the $before value in the source array.

bool $splatInsertArray

If true, $insert must be an array. Its values will be splatted into the source array.

Return Value

array