Util/Array.php
\Conjoon_Util_Array
Utility methods for working with arrays.
- Author
- Thorsten Suckow-Homberg
- Category
- Util
Methods

_apply(
$array1, $array2, $strict
=
false, $preserveExisting
=
false
)
:
void| Name | Type | Description |
|---|---|---|
| $array1 | ||
| $array2 | ||
| $strict | ||
| $preserveExisting |

_isAssocCallback(
$a, $b
)
:
voidCallback for array_reduce-function used in isAssociative
| Name | Type | Description |
|---|---|---|
| $a | ||
| $b |

apply(
array $array1, array $array2
)
:
voidApplies the key/value pairs from array 2 to array 1.
Overwrites existing keys.
| Name | Type | Description |
|---|---|---|
| $array1 | array | |
| $array2 | array |

applyIf(
array $array1, array $array2
)
:
voidApplies the key/value pairs from array 2 to array 1, if, and only if this key is not already set in array 1.
| Name | Type | Description |
|---|---|---|
| $array1 | array | |
| $array2 | array |

applyStrict(
array $array1, array $array2
)
:
voidApplies the key/value pairs from array 2 to array 1, if, and only if the key for the value exists in $array1.
| Name | Type | Description |
|---|---|---|
| $array1 | array | |
| $array2 | array |

arrayKeysExist(
array $array, array $keys
)
:
boolean | stringChecks whether a given array provides the listed keys.
The method will eitehr return true if all keys are available or the name of the first key that was missing.
| Name | Type | Description |
|---|---|---|
| $array | array | The associative array to check |
| $keys | array | The list of keys to check for availability in $array |
| Type | Description |
|---|---|
| boolean | string | either true if none of the keys in $list was missing as a key in $array, or the name of the first key that was found missing |

camelizeKeys(
Array $array, boolean $return
=
false
)
:
ArrayCamelizes the keys of an assoziative array and returns the array with the new keys, if the second parameter is set to "true".
Otherwise, the reference to the passed argument will be used and the array will be changed directly.
| Name | Type | Description |
|---|---|---|
| $array | Array | The associative array to camelize the keys. |
| $return | boolean | "true" for return a copy of the array with the camelized keys, otherwise false |
| Type | Description |
|---|---|
| Array | The new array with the keys camelized or null, if the reference is used |
- Deprecated
- use camelizeKeys2 instead

extractByKeys(
array $array, array $keys
)
:
boolean | arrayExtracts the specified keys from the array and saves them into a new array with their according values.
| Name | Type | Description |
|---|---|---|
| $array | array | The associative array to extract data from |
| $keys | array | The list of keys which values should be extracted from $array |
| Type | Description |
|---|---|
| boolean | array | either false if a key was missing in $array, or a new array with the extracted values |

isAssociative(
array $array
)
:
\bolleanChecks wether the passed argument is an associative array.
| Name | Type | Description |
|---|---|---|
| $array | array | The array to check for associative keys |
| Type | Description |
|---|---|
| \bollean | "true", if the array is associative, otherwise "false" |

underscoreKeys(
Array $array, boolean $return
=
false
)
:
ArrayUnderscores the keys of an assoziative array (if camelized) and returns the array with the new keys, if the second parameter is set to "true".
Otherwise, the reference to the passed argument will be used and the array will be changed directly.
| Name | Type | Description |
|---|---|---|
| $array | Array | The associative array to underscore the keys. |
| $return | boolean | "true" for return a copy of the array with the underscored keys, otherwise false |
| Type | Description |
|---|---|
| Array | The new array with the keys underscored or null, if the reference is used |