php中的DS,PHP Ds\Set union()用法及代码示例

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)

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值