array_union

This function returns a new array that is the union of all provided arrays. A union refers to all the elements in the provided arrays, with duplicates removed.

NOTE The order of elements in the new array is not ensured. If you need to sort the array you will need to do so afterwards.

Syntax:

array_union(array0, [array1, ... array_n]);

Argument Type Description
array0 Array The first array
[array1, ... array_n] Array OPTIONAL Any number of arrays for union (one array per argument)

Returns:

Array (the union of the provided arrays)

 

Example:

a1 = [1, 2, 3, 4, 5];
a2 = [3, 4, 5, 6, 7, 8];
a3 = [5, 6, 7, 8, 9, 10, 11];

a4 = array_union(a1, a2, a3);

The above code first creates 3 arrays a1, a2 and a3. It then takes the union of these arrays and stores the result in a new array a4.