TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ArrayUtility Class Reference

Static Public Member Functions

static integerExplode ($delimiter, $string)
 
static trimExplode ($delimiter, $string, $onlyNonEmptyValues=false)
 
static arrayMergeRecursiveOverrule (array $firstArray, array $secondArray, $dontAddNewKeys=false, $emptyValuesOverride=true)
 
static randomizeArrayOrder (array $array)
 
static containsMultipleTypes (array $array)
 
static array_reduce (array $array, $function, $initial=null)
 
static getValueByPath (array &$array, $path)
 
static setValueByPath ($subject, $path, $value)
 
static unsetValueByPath (array $array, $path)
 
static sortKeysRecursively (array &$array, $sortFlags=null)
 
static convertObjectToArray ($subject)
 
static removeEmptyElementsRecursively (array $array)
 
static sortArrayWithIntegerKeys ($array)
 

Detailed Description

The array functions from good old GeneralUtility plus new code. This class has been deprecated as PHP's native functionality and the Core's own ArrayUtility provides the same functionality. Do not use it anymore, it will be removed in TYPO3 v9.

Definition at line 26 of file extbase/Classes/Utility/ArrayUtility.php.

Member Function Documentation

static array_reduce ( array  $array,
  $function,
  $initial = null 
)
static

Replacement for array_reduce that allows any type for $initial (instead of only integer)

Parameters
array$arraythe array to reduce
string$functionthe reduce function with the same order of parameters as in the native array_reduce (i.e. accumulator first, then current array element)
mixed$initialthe initial accumulator value
Returns
mixed
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9

Definition at line 172 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

static arrayMergeRecursiveOverrule ( array  $firstArray,
array  $secondArray,
  $dontAddNewKeys = false,
  $emptyValuesOverride = true 
)
static

Merges two arrays recursively and "binary safe" (integer keys are overridden as well), overruling similar values in the first array ($firstArray) with the values of the second array ($secondArray) In case of identical keys, ie. keeping the values of the second.

Parameters
array$firstArrayFirst array
array$secondArraySecond array, overruling the first array
bool$dontAddNewKeysIf set, keys that are NOT found in $firstArray (first array) will not be set. Thus only existing value can/will be overruled from second array.
bool$emptyValuesOverrideIf set (which is the default), values from $secondArray will overrule if they are empty (according to PHP's empty() function)
Returns
array Resulting array where $secondArray values has overruled $firstArray values
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9, use array_replace_recursive() instead if possible, other see the ArrayUtility in EXT:core

Definition at line 86 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

static containsMultipleTypes ( array  $array)
static

Returns TRUE if the given array contains elements of varying types

Parameters
array$array
Returns
bool
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9

Definition at line 146 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

static convertObjectToArray (   $subject)
static

Recursively convert an object hierarchy into an associative array.

Parameters
mixed$subjectAn object or array of objects
Exceptions
InvalidArgumentException
Returns
array The subject represented as an array
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9

Definition at line 304 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

Referenced by ArrayUtilityTest\convertObjectToArrayConvertsNestedObjectsToArray().

static getValueByPath ( array &  $array,
  $path 
)
static

Returns the value of a nested array by following the specified path.

Parameters
array&$arrayThe array to traverse as a reference
array | string$pathThe path to follow. Either a simple array of keys or a string in the format 'foo.bar.baz'
Exceptions
InvalidArgumentException
Returns
mixed The value found, NULL if the path didn't exist
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9, use ArrayUtility provided by EXT:core instead.

Definition at line 192 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

Referenced by ArrayUtilityTest\getValueByPathReturnsTheValueOfANestedArrayByFollowingTheGivenPathIfPathIsString(), and ArrayUtilityTest\getValueByPathThrowsExceptionIfPathIsNoArrayOrString().

static integerExplode (   $delimiter,
  $string 
)
static

Explodes a $string delimited by $delimiter and casts each item in the array to (int). Corresponds to explode(), but with conversion to integers for all values.

Parameters
string$delimiterDelimiter string to explode with
string$stringThe string to explode
Returns
array Exploded values, all converted to integers
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9, use GeneralUtility::intExplode()

Definition at line 38 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

static randomizeArrayOrder ( array  $array)
static

Randomizes the order of array values. The array should not be an associative array as the key-value relations will be lost.

Parameters
array$arrayArray to reorder
Returns
array The array with randomly ordered values
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9

Definition at line 123 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

static removeEmptyElementsRecursively ( array  $array)
static

Recursively removes empty array elements.

Parameters
array$array
Returns
array the modified array
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9

Definition at line 328 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

Referenced by ArrayUtilityTest\removeEmptyElementsRecursivelyRemovesEmptySubArrays(), and ArrayUtilityTest\removeEmptyElementsRecursivelyRemovesNullValues().

static setValueByPath (   $subject,
  $path,
  $value 
)
static

Sets the given value in a nested array or object by following the specified path.

Parameters
array | \ArrayAccess$subjectThe array or ArrayAccess instance to work on
array | string$pathThe path to follow. Either a simple array of keys or a string in the format 'foo.bar.baz'
mixed$valueThe value to set
Exceptions
InvalidArgumentException
Returns
array The modified array or object
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9, use ArrayUtility provided by EXT:core instead.

Definition at line 221 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

Referenced by ArrayUtilityTest\setValueByLeavesInputArrayUnchanged(), ArrayUtilityTest\setValueByPathRecursivelyMergesAnArray(), ArrayUtilityTest\setValueByPathSetsValueRecursivelyIfPathIsArray(), ArrayUtilityTest\setValueByPathSetsValueRecursivelyIfPathIsString(), ArrayUtilityTest\setValueByPathThrowsExceptionIfPathIsNoArrayOrString(), ArrayUtilityTest\setValueByPathThrowsExceptionIfSubjectIsNoArray(), and ArrayUtilityTest\setValueByPathThrowsExceptionIfSubjectIsNoArrayAccess().

static sortArrayWithIntegerKeys (   $array)
static

If the array contains numerical keys only, sort it in ascending order

Parameters
array$array
Returns
array
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9, use the same method provided in TYPO3

Definition at line 353 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

Referenced by ArrayUtilityTest\sortArrayWithIntegerKeysSortsNumericArrays().

static sortKeysRecursively ( array &  $array,
  $sortFlags = null 
)
static

Sorts multidimensional arrays by recursively calling ksort on its elements.

Parameters
array&$arraythe array to sort
int$sortFlagsmay be used to modify the sorting behavior using these values (see http://www.php.net/manual/en/function.sort.php)
Returns
bool TRUE on success, FALSE on failure
See also
asort()
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9

Definition at line 283 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

static trimExplode (   $delimiter,
  $string,
  $onlyNonEmptyValues = false 
)
static

Explodes a string and trims all values for whitespace in the ends. If $onlyNonEmptyValues is set, then all blank ('') values are removed.

Parameters
string$delimiterDelimiter string to explode with
string$stringThe string to explode
bool$onlyNonEmptyValuesIf set, all empty values (='') will NOT be set in output
Returns
array Exploded values
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9, use GeneralUtility::trimExplode() instead

Definition at line 60 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

static unsetValueByPath ( array  $array,
  $path 
)
static

Unsets an element/part of a nested array by following the specified path.

Parameters
array$arrayThe array
array | string$pathThe path to follow. Either a simple array of keys or a string in the format 'foo.bar.baz'
Exceptions
InvalidArgumentException
Returns
array The modified array
Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9, see ArrayUtility::removeByPath()

Definition at line 253 of file extbase/Classes/Utility/ArrayUtility.php.

References GeneralUtility\logDeprecatedFunction().

Referenced by ArrayUtilityTest\unsetValueByPathDoesNotModifyAnArrayIfThePathWasNotFound(), ArrayUtilityTest\unsetValueByPathRemovesSpecifiedBranch(), ArrayUtilityTest\unsetValueByPathRemovesSpecifiedKey(), ArrayUtilityTest\unsetValueByPathRemovesSpecifiedKeyIfPathIsString(), and ArrayUtilityTest\unsetValueByPathThrowsExceptionIfPathIsNoArrayOrString().