Class ArrayLib
Library of static methods for manipulating arrays.
Methods summary
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.
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: <example> array( 'row1' => array( 'col1' =>'val1', 'col2'
=> 'val2' ), 'row2' => array( 'col1' => 'val3', 'col2' => 'val4' ) )
</example>
After: <example> array( 'col1' => array( 'row1' => 'val1', 'row2'
=> 'val3', ), 'col2' => array( 'row1' => 'val2', 'row2' => 'val4',
), ) </example>
Parameters
Returns
array array
|
public static
array
|
#
valuekey( mixed $arr )
Return an array where the keys are all equal to the values
Return an array where the keys are all equal to the values
Parameters
Returns
array array
|
public static
|
|
public static
array
|
#
filter_keys( mixed $arr, mixed $keys )
Filter an array by keys (useful for only allowing certain form-input to be
saved).
Filter an array by keys (useful for only allowing certain form-input to be
saved).
Parameters
- $arr
- $arr array
- $keys
- $keys array
Returns
array array
|
public static
boolean
|
#
is_associative( array $arr )
Determines if an array is associative by checking for existing keys via
array_key_exists().
Determines if an array is associative by checking for existing keys via
array_key_exists().
Parameters
Returns
boolean boolean
See
|
public static
boolean
|
#
in_array_recursive( mixed $needle, array $haystack, boolean $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.
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
- $needle
- mixed $needle
- $haystack
- array $haystack
- $strict
- boolean $strict
Returns
boolean boolean
|
Magic methods summary
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-