TYPO3  7.6
Static Public Member Functions | List of all members
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 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

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

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

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

static 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 extbase/Classes/Utility/ArrayUtility.php.

References elseif.

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

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

static 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
\InvalidArgumentException
Returns
mixed The value found, NULL if the path didn't exist

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

References elseif.

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

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

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

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

static removeEmptyElementsRecursively ( array  $array)
static

Recursively removes empty array elements.

Parameters
array$array
Returns
array the modified array

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

References elseif.

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

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

References elseif.

static sortArrayWithIntegerKeys (   $array)
static

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

Parameters
array$array
Returns
array

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

Referenced by StandaloneView\buildListOfTemplateCandidates(), and ActionController\getViewProperty().

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()

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

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

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

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

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

References elseif.