Zum Hauptinhalt springen

Array complement

Anatomy

<array:complement var="var" var_set="var" var_result="(destructive on 'var')" type="values"/>

Description: ARRAY:COMPLEMENT generates the relative complement of two arrays by extracting those items of an array that do not exist within the set array.

Attention:

ARRAY:COMPLEMENT 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:complement
var_setvarSet variable name array:complement
var_resultvarResult variable name array:complement
typetypeComplement type array:complement

Results:

BindingTypePredicate
varvar_resultarray

Examples

Complement by keys

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

<array var="complement">
<item key="bg">Bill Gates</item>
</array>

<array:complement var="names" var_set="complement" type="keys"/>
<output>$names.sj and $names.le are friends!</output>

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

Complement by values

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

<array var="complement">
<item>Bill Gates</item>
</array>

<array:complement var="names" var_set="complement" type="values"/>
<output>$names[1] and $names[2] are friends!</output>

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