Ds \ Set::union()函数是PHP中的内置函数,用于创建包含两个集合的并集的新集合。
用法:
Ds\Set public Ds\Set::union ( Ds\Set $set )
参数:该函数接受单个参数$set,该参数保存实例的另一组以与当前实例结合。
返回值:它返回一个包含两个集合的并集的集合。
以下示例程序旨在说明PHP中的Ds \ Set::union()函数:
程序1:
// 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
)
程序2:
// 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)
}