array:remove

Returns an array containing all the members of the supplied array, except for the members at specified positions.

Signature

array:remove(
    $array as array(*), 
    $positions as xs:integer*
) as array(*)

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

The function returns an array of size array:size($array) - fn:count(fn:distinct-values($positions)) containing all members from $array except the members whose position (counting from 1) is present in the sequence $positions. The order of the remaining members is preserved.

The result of the function, except in error cases, is given by the expression array:join(for $i in (1 to array:size($array))[not(. = $positions)] return [$array($i)])

Error Conditions

A dynamic error is raised [ERRFOAY0001] if any integer in $positions is not in the range 1 to array:size($array) inclusive. By implication, an error occurs if $array is empty, unless $positions is also empty.

Examples

The expression array:remove(["a", "b", "c", "d"], 1) returns ["b", "c", "d"].

The expression array:remove(["a", "b", "c", "d"], 2) returns ["a", "c", "d" ].

The expression array:remove(["a"], 1) returns [ ].

The expression array:remove(["a", "b", "c", "d"], 1 to 3) returns ["d"].

The expression array:remove(["a", "b", "c", "d"], ()) returns ["a", "b", "c", "d"].