hphp/hack/manual/hsl/Functions/HH.Lib.Keyset/union.md
:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::
Returns a new keyset containing all of the elements of the given Traversables
namespace HH\Lib\Keyset;
function union<Tv as arraykey>(
Traversable<Tv> $first,
Container<Tv> ...$rest,
): keyset<Tv>;
For a variable number of Traversables, see Keyset\flatten().
Time complexity: O(n + m), where n is the size of $first and m is the
combined size of all the ...$rest
Space complexity: O(n + m), where n is the size of $first and m is the
combined size of all the ...$rest
Traversable<Tv>$firstContainer<Tv>...$restkeyset<Tv>$result = Keyset\union(keyset[1,2], vec[4,5] );
print_r($result);
//result: keyset[1,2,4,5]
$result = Keyset\union(keyset[1,2], vec[3,3,4,5] );
print_r($result);
//result: keyset[1,2,3,4,5]