Click or drag to resize

array.flatten Function

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
array.flatten Function

The array.flatten function expands single array elements (of type array) into multiple elements.

Syntax

Alchemy
array.flatten(ident);

Nomenclature

identRequired. The array to flatten

Returns

The source array with all elements of type array expanded into multiple elements - 'flattened'.

Example

The following example creates an array with three elements. The first two elements are '1' and '2', the third element is another array containing the elements '3' and '4'. This is shown in the first line of output.

The array is then flattened and shown in the second line of output.

Alchemy
$arr34 = array.new(3, 4);
PRINT $arr34; /* [3,4] */

$arr12 = array.new(1, 2, $arr34);
PRINT $arr12; /* [1,2,[3,4]] */

PRINT array.flatten($arr); /* [1,2,3,4] */

Note how the third element of arr12 (which is arr34) has been 'flattened' to two separate elements in the arr12 array. The above code snippet produces the following output:

[3,4]

[1,2,[3,4]]

[1,2,3,4]

See Also

  • array.first - get the first element of an array

  • array.join - convert an array to a string by joining all the elements

  • array.last - get the last element of an array

  • array.new - create a new array

  • array.range - return a sub-array from a specified array

  • array.set_at - modify the data at a specified index of an array

  • array.get_at - retrieve the data at a specified index of an array

  • length - get the number of elements in an array