Got a question that the wiki doesn't answer? Ask on the forum (preferred), or join us on IRC.


CommandHelper/Staged/API/array merge

From Wiki
Jump to: navigation, search

Vital Info

Name array_merge
Returns array
Usages array1, array2, [arrayN...]
Throws InsufficientArgumentsException


Since 3.3.0
Optimizations NO_SIDE_EFFECTS


Merges the specified arrays from left to right, and returns a new array. If the array merged is associative, it will overwrite the keys from left to right, but if the arrays are normal, the keys are ignored, and values are simply pushed.


array_merge(array1, array2, [arrayN...])

Examples (How do these work?)

Example 1

Basic usage

Given the following code:

1   array_merge(array(1), array(2), array(3))

The output would be:

:{1, 2, 3}

Example 2

With associative arrays

Given the following code:

1   array_merge(array(one: 1), array(two: 2), array(three: 3))

The output would be:

:{one: 1, three: 3, two: 2}

Example 3

With overwrites

Given the following code:

1   array_merge(array(one: 1), array(one: 2), array(one: 3))

The output would be:

:{one: 3}

Navigation menu