Skip to main content

Extract array items

Anatomy

<array:extract var="var" var_replacement="var" var_result="var" offset="int" length="(end of array)"/>

Description: ARRAY:EXTRACT extracts and replaces part of an array, isolated by an offset and a length.

If the offset is negative it will start that many items from the end of the array. If the length is omitted, every item from the offset until the end of the array will be returned. If the length is negative then it will stop that many items from the end of the array.

Attention:

ARRAY:EXTRACT is destructive, in the sense that it modifies the array in-place. It will re-index all keys in the array numerically.

Attributes

NameTypeDescriptionDefined By
varvarVariable name array:extract
var_replacementvarReplacement variable name array:extract
var_resultvarResult variable name array:extract
offsetintOffset array:extract
lengthintLength array:extract

Results:

BindingTypePredicate
vararrayno-result-propagation
var_resultarrayno-result-propagation

Examples

Extraction

<array var="names">
<item>Bill Gates</item>
<item>Steve Jobs</item>
<item>Larry Ellison</item>
</array>

<array:extract var="names" var_result="extract" offset="1" length="2"/>
<output>$extract[0] and $extract[1] are friends!</output>

<!-- Steve Jobs and Larry Ellison are friends! -->

Replacement

<array var="names">
<item>Bill Gates</item>
<item>Larry Ellison</item>
</array>

<array var="replacement">
<item>Steve Jobs</item>
</array>

<array:extract var="names" var_replacement="replacement" length="1"/>
<output>$names[0] and $names[1] are friends!</output>

<!-- Steve Jobs and Larry Ellison are friends! -->