<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.array.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.array-intersect-ukey.php',
    1 => 'array_intersect_ukey',
    2 => 'Computes the intersection of arrays using a callback function on the keys for comparison',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Array Functions',
  ),
  'prev' => 
  array (
    0 => 'function.array-intersect-uassoc.php',
    1 => 'array_intersect_uassoc',
  ),
  'next' => 
  array (
    0 => 'function.array-is-list.php',
    1 => 'array_is_list',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/array/functions/array-intersect-ukey.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-intersect-ukey" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_intersect_ukey</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_intersect_ukey</span> &mdash; <span class="dc-title">Computes the intersection of arrays using a callback function on the keys for comparison</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.array-intersect-ukey-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_intersect_ukey</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$array</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">...$arrays</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> <code class="parameter">$key_compare_func</code></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>array_intersect_ukey()</strong></span> returns an array
   containing all the values of <code class="parameter">array</code>
   which have matching keys that are present in all the arguments.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-intersect-ukey-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       Initial array for comparison of the arrays.
      </p>
     </dd>
    
    
     <dt><code class="parameter">arrays</code></dt>
     <dd>
      <p class="para">
       Arrays to compare keys against.
      </p>
     </dd>
    
    
     <dt><code class="parameter">key_compare_func</code></dt>
     <dd>
      <p class="para">
 The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
</p>
<div class="methodsynopsis dc-description"><span class="methodname"><span class="replaceable">callback</span></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$a</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$b</code></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

<div class="caution"><strong class="caution">Caution</strong>
 <p class="para">
  Returning <em>non-integer</em> values from the comparison
  function, such as <span class="type"><a href="language.types.float.php" class="type float">float</a></span>, will result in an internal cast to
  <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> of the callback&#039;s return value. So values such as
  <code class="literal">0.99</code> and <code class="literal">0.1</code> will both be cast to an
  integer value of <code class="literal">0</code>, which will compare such values as equal.
 </p>
</div>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-intersect-ukey-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the values of <code class="parameter">array</code> whose keys exist
   in all the arguments.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-intersect-ukey-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>array_intersect_ukey()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">key_compare_func</span><span style="color: #007700">(</span><span style="color: #0000BB">$key1</span><span style="color: #007700">, </span><span style="color: #0000BB">$key2</span><span style="color: #007700">)<br />{<br />    if (</span><span style="color: #0000BB">$key1 </span><span style="color: #007700">== </span><span style="color: #0000BB">$key2</span><span style="color: #007700">)<br />        return </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />    else if (</span><span style="color: #0000BB">$key1 </span><span style="color: #007700">&gt; </span><span style="color: #0000BB">$key2</span><span style="color: #007700">)<br />        return </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />    else<br />        return -</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$array1 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'blue'  </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">'red'  </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #DD0000">'green'  </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #DD0000">'purple' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$array2 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'green' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #DD0000">'blue' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">6</span><span style="color: #007700">, </span><span style="color: #DD0000">'yellow' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">7</span><span style="color: #007700">, </span><span style="color: #DD0000">'cyan'   </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">8</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">array_intersect_ukey</span><span style="color: #007700">(</span><span style="color: #0000BB">$array1</span><span style="color: #007700">, </span><span style="color: #0000BB">$array2</span><span style="color: #007700">, </span><span style="color: #DD0000">'key_compare_func'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(2) {
  [&quot;blue&quot;]=&gt;
  int(1)
  [&quot;green&quot;]=&gt;
  int(3)
}</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   In our example you see that only the keys <code class="literal">&#039;blue&#039;</code>
   and <code class="literal">&#039;green&#039;</code> are present in both arrays and thus
   returned. Also notice that the values for the keys
   <code class="literal">&#039;blue&#039;</code> and <code class="literal">&#039;green&#039;</code> differ between
   the two arrays. A match still occurs because only the keys are checked.
   The values returned are those of <code class="parameter">array</code>.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-intersect-ukey-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.array-diff.php" class="function" rel="rdfs-seeAlso">array_diff()</a> - Computes the difference of arrays</span></li>
    <li><span class="function"><a href="function.array-udiff.php" class="function" rel="rdfs-seeAlso">array_udiff()</a> - Computes the difference of arrays by using a callback function for data comparison</span></li>
    <li><span class="function"><a href="function.array-diff-assoc.php" class="function" rel="rdfs-seeAlso">array_diff_assoc()</a> - Computes the difference of arrays with additional index check</span></li>
    <li><span class="function"><a href="function.array-diff-uassoc.php" class="function" rel="rdfs-seeAlso">array_diff_uassoc()</a> - Computes the difference of arrays with additional index check which is performed by a user supplied callback function</span></li>
    <li><span class="function"><a href="function.array-udiff-assoc.php" class="function" rel="rdfs-seeAlso">array_udiff_assoc()</a> - Computes the difference of arrays with additional index check, compares data by a callback function</span></li>
    <li><span class="function"><a href="function.array-udiff-uassoc.php" class="function" rel="rdfs-seeAlso">array_udiff_uassoc()</a> - Computes the difference of arrays with additional index check, compares data and indexes by a callback function</span></li>
    <li><span class="function"><a href="function.array-diff-key.php" class="function" rel="rdfs-seeAlso">array_diff_key()</a> - Computes the difference of arrays using keys for comparison</span></li>
    <li><span class="function"><a href="function.array-diff-ukey.php" class="function" rel="rdfs-seeAlso">array_diff_ukey()</a> - Computes the difference of arrays using a callback function on the keys for comparison</span></li>
    <li><span class="function"><a href="function.array-intersect.php" class="function" rel="rdfs-seeAlso">array_intersect()</a> - Computes the intersection of arrays</span></li>
    <li><span class="function"><a href="function.array-intersect-assoc.php" class="function" rel="rdfs-seeAlso">array_intersect_assoc()</a> - Computes the intersection of arrays with additional index check</span></li>
    <li><span class="function"><a href="function.array-intersect-uassoc.php" class="function" rel="rdfs-seeAlso">array_intersect_uassoc()</a> - Computes the intersection of arrays with additional index check, compares indexes by a callback function</span></li>
    <li><span class="function"><a href="function.array-intersect-key.php" class="function" rel="rdfs-seeAlso">array_intersect_key()</a> - Computes the intersection of arrays using keys for comparison</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>