TYPO3 CMS  TYPO3_6-2
TYPO3\CMS\Extbase\Utility\ArrayUtility Class Reference
Inheritance diagram for TYPO3\CMS\Extbase\Utility\ArrayUtility:
Tx_Extbase_Utility_Arrays

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

This file is part of the TYPO3 CMS project.

It is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, either version 2 of the License, or any later version.

For the full copyright and license information, please read the LICENSE.txt file that was distributed with this source code.

The TYPO3 project - inspiring people to share! 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 152 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
boolean$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.
boolean$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 75 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
boolean

Definition at line 129 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 270 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 169 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 $delimeter 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 109 of file ArrayUtility.php.

◆ removeEmptyElementsRecursively()

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

Recursively removes empty array elements.

Parameters
array$array
Returns
array the modified array

Definition at line 291 of file ArrayUtility.php.

References $result.

Referenced by TYPO3\CMS\Extbase\Tests\Unit\Utility\ArrayUtilityTest\removeEmptyElementsRecursivelyRemovesEmptySubArrays(), and TYPO3\CMS\Extbase\Tests\Unit\Utility\ArrayUtilityTest\removeEmptyElementsRecursivelyRemovesNullValues().

◆ 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
integer$sortFlagsmay be used to modify the sorting behavior using these values (see http://www.php.net/manual/en/function.sort.php)
Returns
boolean TRUE on success, FALSE on failure
See also
asort()

Definition at line 252 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
boolean$onlyNonEmptyValuesIf set, all empty values (='') will NOT be set in output
Returns
array Exploded values

Definition at line 52 of file ArrayUtility.php.

◆ unsetValueByPath()

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