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

Ds \ Set::xor()函数是PHP中的内置函数,用于创建一个新集合,该集合包含第一组或第二组中的值,但不能同时包含两者。

用法:

Ds\Set public Ds\Set::xor ( Ds\Set $set )

参数:该函数接受单个参数$set,该参数用于保存值集。

返回值:它用于返回一个集合,该集合包含当前集合与另一个集合的异或。

以下示例程序旨在说明PHP中的Ds \ Set::xor()函数:

程序1:

// Declare a new set

$a = new \Ds\Set([1, 3, 5]);

// Declare a new set

$b = new \Ds\Set([2, 3, 6]);

// Print the xor of both set

echo("xor of both set is:\n");

print_r($a->xor($b));

?>

输出:

xor of both set is:

Ds\Set Object

(

[0] => 1

[1] => 5

[2] => 2

[3] => 6

)

程序2:

// Declare a new set

$a = new \Ds\Set([2, 3, 6, 7, 8]);

// Declare a new set

$b = new \Ds\Set([2, 3, 5, 8, 9, 10]);

// Print the xor of both set

echo("xor of both set is:\n");

var_dump($a->xor($b));

?>

输出:

xor of both set is:

object(Ds\Set)#3 (5) {

[0]=>

int(6)

[1]=>

int(7)

[2]=>

int(5)

[3]=>

int(9)

[4]=>

int(10)

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值