In PHP, you can find the union of two sets using the array_merge function or the union operator.
In this example,
$set1
and $set2
.array_merge
function to merge $set2
into $set1
.<?php
$set1 = [1, 2, 3];
$set2 = [3, 4, 5];
$union = array_merge($set1, $set2);
print_r($union);
[1, 2, 3, 3, 4, 5]
In this example,
$set1
and $set2
.+
) to merge $set2
into $set1
.<?php
$set1 = [1, 2, 3];
$set2 = [3, 4, 5];
$union = $set1 + $set2;
print_r($union);
[1, 2, 3, 4, 5]
In this tutorial, we learned How to find Union of Two Sets in PHP language with well detailed examples.