array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'ds-map.intersect.php', 1 => 'Ds\\Map::intersect', ), 'up' => array ( 0 => 'class.ds-map.php', 1 => 'Ds\\Map', ), 'prev' => array ( 0 => 'ds-map.hasvalue.php', 1 => 'Ds\\Map::hasValue', ), 'next' => array ( 0 => 'ds-map.isempty.php', 1 => 'Ds\\Map::isEmpty', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/ds/ds/map/intersect.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PECL ds >= 1.0.0)
Ds\Map::intersect — Creates a new map by intersecting keys with another 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}
注意:
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
.
示例 #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) } }