Skip to main content

Replace array items

Anatomy

<array:replace var="var" var_replacement="var" var_result="(destructive on 'var')"/>

Description: ARRAY:REPLACE replaces the values of an array with the values of a replacement array based on their common keys.

Attention:

ARRAY:REPLACE is destructive, in the sense that it modifies the array in-place, unless 'var_result' is specified in which case a copy of the resulting array will be stored in 'var_result' instead. It preserves the key and value associations of the array.

Attributes

NameTypeDescriptionDefined By
varvarVariable name array:replace
var_replacementvarReplacement variable name array:replace
var_resultvarResult variable name array:replace

Results:

BindingTypePredicate
varvar_resultarray

Examples

Example

<array var="names">
<item key="bg">Bill Gates</item>
<item key="sj">Steve Jobs</item>
</array>

<array var="replacement">
<item key="bg">William Henry Gates III</item>
</array>

<array:replace var="names" var_replacement="replacement"/>
<output>$names.bg and $names.sj are competitors!</output>

<!-- William Henry Gates III and Steve Jobs are competitors! -->