Ds \ Set::union()函數是PHP中的內置函數,用於創建包含兩個集合的並集的新集合。
用法:
Ds\Set public Ds\Set::union ( Ds\Set $set )
參數:該函數接受單個參數$set,該參數保存實例的另一組以與當前實例結合。
返回值:它返回一個包含兩個集合的並集的集合。
以下示例程序旨在說明PHP中的Ds \ Set::union()函數:
程序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
)
程序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)
}
參考: https://www.php.net/manual/en/ds-set.union.php
相關用法
- PHP Ds\Map union()用法及代碼示例
- underscore.js _.union()用法及代碼示例
- PHP max( )用法及代碼示例
- PHP tan( )用法及代碼示例
- PHP end()用法及代碼示例
- p5.js box()用法及代碼示例
- PHP min( )用法及代碼示例
- p5.js arc()用法及代碼示例
- PHP abs()用法及代碼示例
- PHP pos()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Ds\Set union() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
