php8.5
Home/ Manual/ ds / set/ Ds\Set::intersect

Ds\Set::intersect

PHP function Edit on GitHub ✎

(PECL ds >= 1.0.0)

Creates a new set by intersecting values with another set

Description

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

Creates a new set using values common to both the current instance and another set. In other words, returns a copy of the current instance with all values removed that are not in the other set.

A ∩ B = {x : x ∈ A ∧ x ∈ B}

Parameters

set

The other set.

Return Values

The intersection of the current instance and another set.

See Also

  • Intersection on Wikipedia

Examples

Ds\Set::intersect() example

php
<?php
$a = new \Ds\Set([1, 2, 3]);
$b = new \Ds\Set([3, 4, 5]);

var_dump($a->intersect($b));
?>

The above example will output something similar to:

output
object(Ds\Set)#3 (1) {
  [0]=>
  int(3)
}

Source: reference/ds/ds/set/intersect.xml · from the official PHP manual (php/doc-en)