class ArrayLib (View source)

Library of static methods for manipulating arrays.

Methods

public static 
array
invert(array $arr)

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)

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

public static 
array_values_recursive($arr)

No description

public static 
array
filter_keys($arr, $keys)

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

public static 
bool
is_associative(array $arr)

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)

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

public static 
array
array_map_recursive($f, $array)

Similar to array_map, but recurses when arrays are encountered.

public static 
array
array_merge_recursive(array $array)

Recursively merges two or more arrays.

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

Takes an multi dimension array and returns the flattened version.

Details

static array invert(array $arr)

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)

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

Parameters

$arr array

Return Value

array

static array_values_recursive($arr)

No description

Improve documentation

Parameters

$arr

static array filter_keys($arr, $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 $arr)

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

Parameters

array $arr

Return Value

bool

See also

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

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

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)

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)

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 = array())

Takes an multi dimension array and returns the flattened version.

Parameters

array $array
bool $preserveKeys
array $out

Return Value

array