$set1 = array(1, 2, 3, 4); $set2 = array(3, 4, 5, 6); $result = array_unique(array_merge($set1, $set2)); print_r($result); // Output: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
$set1 = array(1, 2, 3, 4); $set2 = array(3, 4, 5, 6); $result = array_intersect($set1, $set2); print_r($result); // Output: Array ( [2] => 3 [3] => 4 )In this example, we have two sets $set1 and $set2. We use array_intersect function to find the common elements in both sets. The resultant array contains the elements that are present in both sets. Package library: PHP Set Combine.