<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Creates a new map by intersecting keys with another map</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds-map.hasvalue.html">Ds\Map::hasValue</a></div> <div class="next" style="text-align: right; float: right;"><a href="ds-map.isempty.html">Ds\Map::isEmpty</a></div> <div class="up"><a href="class.ds-map.html">Map</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="ds-map.intersect" class="refentry"> <div class="refnamediv"> <h1 class="refname">Ds\Map::intersect</h1> <p class="verinfo">(PECL ds >= 1.0.0)</p><p class="refpurpose"><span class="refname">Ds\Map::intersect</span> — <span class="dc-title">Creates a new map by intersecting keys with another map</span></p> </div> <div class="refsect1 description" id="refsect1-ds-map.intersect-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><span class="type Ds\Map">Ds\Map</span></span> <span class="methodname"><strong>Ds\Map::intersect</strong></span> ( <span class="methodparam"><span class="type"><span class="type Ds\Map">Ds\Map</span></span> <code class="parameter">$map</code></span> )</div> <p class="para rdfs-comment"> Creates a new map containing the pairs of the current instance whose keys are also present in the given <code class="parameter">map</code>. In other words, returns a copy of the current instance with all keys removed that are not also in the other <code class="parameter">map</code>. </p> <p class="para"> <code class="code">A ∩ B = {x : x ∈ A ∧ x ∈ B}</code> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Values from the current instance will be kept. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-ds-map.intersect-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">map</code></dt> <dd> <p class="para"> The other map, containing the keys to intersect with. </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-ds-map.intersect-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The key intersection of the current instance and another <code class="parameter">map</code>. </p> </div> <div class="refsect1 seealso" id="refsect1-ds-map.intersect-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="https://en.wikipedia.org/wiki/Intersection_(set_theory)" class="link external">» Intersection</a> on Wikipedia</li> </ul> </p> </div> <div class="refsect1 examples" id="refsect1-ds-map.intersect-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-5263"> <p><strong>Example #1 <span class="function"><strong>Ds\Map::intersect()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$a </span><span style="color: #007700">= new \</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Map</span><span style="color: #007700">([</span><span style="color: #DD0000">"a" </span><span style="color: #007700">=> </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">"b" </span><span style="color: #007700">=> </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #DD0000">"c" </span><span style="color: #007700">=> </span><span style="color: #0000BB">3</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">$b </span><span style="color: #007700">= new \</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Map</span><span style="color: #007700">([</span><span style="color: #DD0000">"b" </span><span style="color: #007700">=> </span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #DD0000">"c" </span><span style="color: #007700">=> </span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #DD0000">"d" </span><span style="color: #007700">=> </span><span style="color: #0000BB">6</span><span style="color: #007700">]);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">-></span><span style="color: #0000BB">intersect</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> 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) } } </pre></div> </div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds-map.hasvalue.html">Ds\Map::hasValue</a></div> <div class="next" style="text-align: right; float: right;"><a href="ds-map.isempty.html">Ds\Map::isEmpty</a></div> <div class="up"><a href="class.ds-map.html">Map</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>