• PHP Video Tutorials

PHP - Ds Set intersect() Function



Ds\Set::intersect() function can create a new set by intersecting the values with another set.

Syntax

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

Ds\Set::intersect() function can create a new set by using the values common to both the current instance and another set. It means returning a copy of the current instance with all values removed that are not in the other set.

Ds\Set::intersect() function can return the intersection of current instance and another set.

Example 1

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

Example 2

<?php  
   $set1 = new \Ds\Set([1, 4, 5, 7, 9]);  
   $set2 = new \Ds\Set([2, 4, 6, 8, 10]);  
      
   echo("The intersection of both set: \n");  
   var_dump($set1->intersect($set2)); 
?> 
php_function_reference.htm
Advertisements