I\'m looking for a simple way to create an array in php that will not allow duplicate entries, but allows for easy combining of other sets or arrays.
I\'m mostly int
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.
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);