Skip to main content

Flip array

XML
<array:flip var="var" var_result="(destructive on 'var')"/>

<array:flip /> exchanges all keys in an array with their associated values.

Attention:

ARRAY:FLIP 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. A distinct array with string-recasted values as keys will be created. If a value has several occurrences within the array, only the last key will be used while all other items with that particular key will be discarded.

Attributes

NameTypeDescriptionDefined By
varvarVariable name array:flip
var_resultvarResult variable name array:flip

Results

BindingTypePredicate
varvar_resultarray

Examples

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

<array:flip var="names"/>
<output>$names[Bill Gates] and $names[Steve Jobs] are competitors!</output>

<!-- bg and sj are competitors! -->