Ds\Map::intersect

(PECL ds >= 1.0.0)

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

说锟斤拷

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}

Note:

Values from the current instance will be kept.

锟斤拷锟斤拷

map

The other map, containing the keys to intersect with.

锟斤拷锟斤拷值

The key intersection of the current instance and another map.

See Also

锟斤拷锟斤拷

Example #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));
?>

锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�

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)
  }
}