Skip to main content

Array Construction

array — Build array​

Full reference →

The ARRAY command is the primary mechanism for constructing structured data in iXML. It creates an associative array (a collection of key-value pairs) and binds it to a variable.

Syntax​

XML
<array var="variableName">
<item key="key1">value1</item>
<item key="key2">value2</item>
</array>

Attributes​

NameTypeRequiredDefaultDescription
varvarYes—The variable name to bind the resulting array to.
keystringNo(next consecutive numeric key)When used as a nested element, specifies the key in the parent array.

Examples​

Array with explicit string keys:

XML
<array var="names">
<item key="bg">Bill Gates</item>
<item key="sj">Steve Jobs</item>
</array>
<output>$names.bg and $names.sj are competitors!</output>

Array with implicit numeric keys:

XML
<array var="names">
<item>Bill Gates</item>
<item>Steve Jobs</item>
</array>
<output>$names[0] and $names[1] are competitors!</output>

item — Array item​

Full reference →

The ITEM command defines a single key-value pair within an <array> construct.

Syntax​

XML
<item key="keyName">value</item>
<item>value</item>

Attributes​

NameTypeRequiredDefaultDescription
varvarNo—Variable name. When specified, the item's value is also stored in this variable independently.
keystringNo(next consecutive numeric key)The key for this item within the parent array.

array:range — Create numeric range array​

Full reference →

The ARRAY:RANGE command creates an array populated with values from a numeric range.

Syntax​

XML
<array:range var="variableName" from="start" to="end" />
<array:range var="variableName" from="start" to="end" step="increment" />

Attributes​

NameTypeRequiredDefaultDescription
varvarYes—The variable name to bind the resulting array to.
fromintYes—The starting value of the range (inclusive).
tointYes—The ending value of the range (inclusive).
stepintNo1The increment between consecutive values.

Example​

XML
<array:range var="range" from="6" to="10" step="2" />
<!-- Result: [6, 8, 10] -->

array:assoc — Associate keys and values​

Full reference →

The ARRAY:ASSOC command creates a new associative array by combining parallel arrays of keys and values.

Syntax​

XML
<array:assoc var="result" var_keys="keysArray" var_values="valuesArray" />

Example​

XML
<array var="keys"><item>bg</item><item>sj</item></array>
<array var="values"><item>Bill Gates</item><item>Steve Jobs</item></array>
<array:assoc var="names" var_keys="keys" var_values="values" />
<!-- Result: {"bg": "Bill Gates", "sj": "Steve Jobs"} -->

array:populate — Import array into variable scope​

Full reference →

The ARRAY:POPULATE command takes all key-value pairs from an array and imports them into the local variable scope as individual variables.

Syntax​

XML
<array:populate var="sourceArray" prefix="prefix_" />

Attributes​

NameTypeRequiredDefaultDescription
varvarYes—The source array.
prefixstringNo—A prefix prepended to each key to form the variable name.

Example​

XML
<array var="data"><item key="id">123</item></array>
<array:populate var="data" prefix="user_" />
<output>User ID: $user_id</output>