TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Extbase\Utility\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.

Definition at line 22 of file ArrayUtility.php.

Member Function Documentation

◆ array_reduce()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::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

Definition at line 157 of file ArrayUtility.php.

◆ arrayMergeRecursiveOverrule()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::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

Definition at line 77 of file ArrayUtility.php.

Referenced by TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder\loadDefaultValues().

◆ containsMultipleTypes()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::containsMultipleTypes ( array  $array)
static

Returns TRUE if the given array contains elements of varying types

Parameters
array$array
Returns
bool

Definition at line 133 of file ArrayUtility.php.

◆ convertObjectToArray()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::convertObjectToArray (   $subject)
static

Recursively convert an object hierarchy into an associative array.

Parameters
mixed$subjectAn object or array of objects
Exceptions

Definition at line 279 of file ArrayUtility.php.

Referenced by TYPO3\CMS\Extbase\Tests\Unit\Utility\ArrayUtilityTest\convertObjectToArrayConvertsNestedObjectsToArray().

◆ getValueByPath()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::getValueByPath ( array &  $array,
  $path 
)
static

Returns the value of a nested array by following the specifed 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

Definition at line 175 of file ArrayUtility.php.

Referenced by TYPO3\CMS\Extbase\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathReturnsTheValueOfANestedArrayByFollowingTheGivenPathIfPathIsString(), TYPO3\CMS\Extbase\Tests\Unit\Utility\ArrayUtilityTest\getValueByPathThrowsExceptionIfPathIsNoArrayOrString(), and TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder\untangleFilesArray().

◆ integerExplode()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::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

Definition at line 33 of file ArrayUtility.php.

◆ randomizeArrayOrder()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::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

Definition at line 112 of file ArrayUtility.php.

◆ removeEmptyElementsRecursively()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively ( array  $array)
static

◆ setValueByPath()

◆ sortArrayWithIntegerKeys()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::sortArrayWithIntegerKeys (   $array)
static

◆ sortKeysRecursively()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::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()

Definition at line 260 of file ArrayUtility.php.

◆ trimExplode()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::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

Definition at line 53 of file ArrayUtility.php.

◆ unsetValueByPath()

static TYPO3\CMS\Extbase\Utility\ArrayUtility::unsetValueByPath ( array  $array,
  $path 
)
static