PHP Class Neos\Eel\Helper\ArrayHelper

The implementation uses the JavaScript specificiation where applicable, including EcmaScript 6 proposals. See https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array for a documentation and specification of the JavaScript implementation.
Inheritance: implements Neos\Eel\ProtectedContextAwareInterface
Datei anzeigen Open project: neos/flow-development-collection Class Usage Examples

Public Methods

Method Description
allowsCallOfMethod ( string $methodName ) : boolean All methods are considered safe
concat ( array | mixed $array1, array | mixed $array2, array | mixed $array_ = null ) : array Concatenate arrays or values to a new array
first ( array $array ) : mixed Get the first element of an array
flip ( array $array ) : array Exchanges all keys with their associated values in an array
indexOf ( array $array, mixed $searchElement, integer $fromIndex = null ) : mixed
isEmpty ( array $array ) : boolean Check if an array is empty
join ( array $array, string $separator = ',' ) : string Join values of an array with a separator
keys ( array $array ) : array Get the array keys
last ( array $array ) : mixed Get the last element of an array
length ( array $array ) : integer Get the length of an array
pop ( array $array ) : array Removes the last element from an array
push ( array $array, mixed $element ) : array Insert one or more elements at the end of an array
random ( array $array ) : mixed Picks a random element from the array
reverse ( array $array ) : array Returns an array in reverse order
shift ( array $array ) : array Remove the first element of an array
shuffle ( array $array, boolean $preserveKeys = true ) : array Shuffle an array
slice ( array $array, string $begin, string $end = null ) : array Extract a portion of an indexed array
sort ( array $array ) : array Sorts an array
splice ( array $array, integer $offset, integer $length = 1, mixed $replacements = null ) : array Replaces a range of an array by the given replacements
unshift ( array $array, mixed $element ) : array Insert one or more elements at the beginning of an array

Method Details

allowsCallOfMethod() public method

All methods are considered safe
public allowsCallOfMethod ( string $methodName ) : boolean
$methodName string
return boolean

concat() public method

Concatenate arrays or values to a new array
public concat ( array | mixed $array1, array | mixed $array2, array | mixed $array_ = null ) : array
$array1 array | mixed First array or value
$array2 array | mixed Second array or value
$array_ array | mixed Optional variable list of additional arrays / values
return array The array with concatenated arrays or values

first() public method

Get the first element of an array
public first ( array $array ) : mixed
$array array The array
return mixed

flip() public method

Note that the values of array need to be valid keys, i.e. they need to be either integer or string. If a value has several occurrences, the latest key will be used as its value, and all others will be lost.
public flip ( array $array ) : array
$array array
return array The array with flipped keys and values

indexOf() public method

public indexOf ( array $array, mixed $searchElement, integer $fromIndex = null ) : mixed
$array array
$searchElement mixed
$fromIndex integer
return mixed

isEmpty() public method

Check if an array is empty
public isEmpty ( array $array ) : boolean
$array array The array
return boolean TRUE if the array is empty

join() public method

Join values of an array with a separator
public join ( array $array, string $separator = ',' ) : string
$array array Array with values to join
$separator string A separator for the values
return string A string with the joined values separated by the separator

keys() public method

Get the array keys
public keys ( array $array ) : array
$array array The array
return array

last() public method

Get the last element of an array
public last ( array $array ) : mixed
$array array The array
return mixed

length() public method

Get the length of an array
public length ( array $array ) : integer
$array array The array
return integer

pop() public method

Note: This differs from the JavaScript behavior of Array.pop which will return the popped element. An empty array will result in an empty array again.
public pop ( array $array ) : array
$array array
return array The array without the last element

push() public method

Allows to push multiple elements at once:: Array.push(array, e1, e2)
public push ( array $array, mixed $element ) : array
$array array
$element mixed
return array The array with the inserted elements

random() public method

Picks a random element from the array
public random ( array $array ) : mixed
$array array
return mixed A random entry or NULL if the array is empty

reverse() public method

Returns an array in reverse order
public reverse ( array $array ) : array
$array array The array
return array

shift() public method

Note: This differs from the JavaScript behavior of Array.shift which will return the shifted element. An empty array will result in an empty array again.
public shift ( array $array ) : array
$array array
return array The array without the first element

shuffle() public method

Randomizes entries an array with the option to preserve the existing keys. When this option is set to FALSE, all keys will be replaced
public shuffle ( array $array, boolean $preserveKeys = true ) : array
$array array
$preserveKeys boolean Wether to preserve the keys when shuffling the array
return array The shuffled array

slice() public method

Extract a portion of an indexed array
public slice ( array $array, string $begin, string $end = null ) : array
$array array The array (with numeric indices)
$begin string
$end string
return array

sort() public method

The sorting is done first by numbers, then by characters. Internally natsort() is used as it most closely resembles javascript's sort(). Because there are no real associative arrays in Javascript, keys of the array will be preserved.
public sort ( array $array ) : array
$array array
return array The sorted array

splice() public method

Allows to give multiple replacements at once:: Array.splice(array, 3, 2, 'a', 'b')
public splice ( array $array, integer $offset, integer $length = 1, mixed $replacements = null ) : array
$array array
$offset integer Index of the first element to remove
$length integer Number of elements to remove
$replacements mixed Elements to insert instead of the removed range
return array The array with removed and replaced elements

unshift() public method

Allows to insert multiple elements at once:: Array.unshift(array, e1, e2)
public unshift ( array $array, mixed $element ) : array
$array array
$element mixed
return array The array with the inserted elements