PHP 8.4.1 Released!

Ds\Map::intersect

(PECL ds >= 1.0.0)

Ds\Map::intersectCreates a new map by intersecting keys with another map

Beschreibung

public Ds\Map::intersect(Ds\Map $map): Ds\Map

Creates a new map containing the pairs of the current instance whose keys are also present in the given map. In other words, returns a copy of the current instance with all keys removed that are not also in the other map.

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

Hinweis:

Values from the current instance will be kept.

Parameter-Liste

map

The other map, containing the keys to intersect with.

Rückgabewerte

The key intersection of the current instance and another map.

Siehe auch

Beispiele

Beispiel #1 Ds\Map::intersect() example

<?php
$a
= new \Ds\Map(["a" => 1, "b" => 2, "c" => 3]);
$b = new \Ds\Map(["b" => 4, "c" => 5, "d" => 6]);

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

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

object(Ds\Map)#3 (2) {
  [0]=>
  object(Ds\Pair)#4 (2) {
    ["key"]=>
    string(1) "b"
    ["value"]=>
    int(2)
  }
  [1]=>
  object(Ds\Pair)#5 (2) {
    ["key"]=>
    string(1) "c"
    ["value"]=>
    int(3)
  }
}
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top