Built in support for sets in PHP?

Just an idea, if you use the array keys instead of values, you'll be sure there are no duplicates, also this allows for easy merging of two "sets".

$set1 = array ('a' => 1, 'b' => 1, );
$set2 = array ('b' => 1, 'c' => 1, );
$union = $set1 + $set2;

The answer is no, there is not a native set solution inside PHP. There is a Set data structure, but that is not baseline PHP.

There is a convention for implementing sets using maps (i.e. associative arrays) in any language. And for PHP you should use true as the bottom value.

<?php

$left = [1=>true, 5=>true, 7=>true];
$right = [6=>true, 7=>true, 8=>true, 9=>true];

$union = $left + $right;
$intersection = array_intersect_assoc($left, $right);

var_dump($left, $right, $union, $intersection);