當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP Ds Set union()用法及代碼示例


Ds\Set::union() 函數可以通過使用來自當前實例和另一個集合的值來創建一個新集合。

用法

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

Ds\Set::union() 函數可以創建一個新的集合,其中包含當前實例的值和另一個集合的值。

Ds\Set::union() 函數可以返回一個包含當前實例的所有值以及另一個集合的新集合。

例子1

<?php 
   $set1 = new \Ds\Set([2, 3, 5]);  
   $set2 = new \Ds\Set([2, 4, 6, 7]);  
   
   echo("The union of both set:\n");  
   print_r($set1-<union($set2)); 
?>

例子2

<?php  
   $set1 = new \Ds\Set([2, 3, 6, 7, 8]);  
   $set2 = new \Ds\Set([2, 3, 5, 8, 9, 10]);  
  
   echo("The union of both set:\n");  
   var_dump($set1->union($set2)); 
?>

相關用法


注:本文由純淨天空篩選整理自 PHP - Ds Set union() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。