The Ds\Set::union() function is an inbuilt function in PHP which is used to create a new set which contains the union of two sets.
Syntax:
Ds\Set public Ds\Set::union ( Ds\Set $set )
Parameters: This function accepts a single parameter $set which holds the other set of the instance to combine with the current instance.
Return value: It returns a set which contains the union of two sets.
Below programs illustrate the Ds\Set::union() function in PHP:
Program 1:
<?php // Declare a new set $a = new \Ds\Set([2, 3, 6]); // Declare another new set $b = new \Ds\Set([2, 4, 6, 7]); // Print the Union of both set echo("Union of both set is: \n"); print_r($a->union($b)); ?> |
Union of both set is:
Ds\Set Object
(
[0] => 2
[1] => 3
[2] => 6
[3] => 4
[4] => 7
)
Program 2:
<?php // Declare a new set $a = new \Ds\Set([2, 3, 6, 7, 8]); // Declare another new set $b = new \Ds\Set([2, 3, 5, 8, 9, 10]); // Print the union of both set echo("Union of both set is: \n"); var_dump($a->union($b)); ?> |
Union of both set is:
object(Ds\Set)#3 (8) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(6)
[3]=>
int(7)
[4]=>
int(8)
[5]=>
int(5)
[6]=>
int(9)
[7]=>
int(10)
}
Reference: https://www.php.net/manual/en/ds-set.union.php
Recommended Posts:
- PHP | Ds\Map union() Function
- TypeScript Union
- Underscore.js | _.union() with Examples
- How to compute union of JavaScript arrays ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | pan() Function
- CSS | hsl() Function
- p5.js | arc() Function
- PHP | pos() Function
- PHP | key() Function
- D3.js | d3.mean() function
- CSS min() Function
- D3.js | d3.sum() function
- PHP | end() Function
- CSS max() Function
- PHP | each() Function
- PHP | each() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

