Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2054

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Computes the difference of arrays with additional index check which is performed by a user supplied callback function</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-diff-key.html">array_diff_key</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-diff-ukey.html">array_diff_ukey</a></div>
 <div class="up"><a href="ref.array.html">Array Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-diff-uassoc" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_diff_uassoc</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">array_diff_uassoc</span> &mdash; <span class="dc-title">Computes the difference of arrays with additional index check which is performed by a user supplied callback function</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.array-diff-uassoc-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_diff_uassoc</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array1</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$array2</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$...</code></span>
   ], <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$key_compare_func</code></span>
   )</div>

  <p class="para rdfs-comment">
   Compares <em><code class="parameter">array1</code></em> against <em><code class="parameter">array2</code></em> and
   returns the difference. Unlike  <span class="function"><a href="function.array-diff.html" class="function">array_diff()</a></span> the array
   keys are used in the comparison.
  </p>
  <p class="para">
   Unlike  <span class="function"><a href="function.array-diff-assoc.html" class="function">array_diff_assoc()</a></span> an user supplied callback
   function is used for the indices comparison, not internal function.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-diff-uassoc-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>


    <dt>

     <span class="term"><em><code class="parameter">array1</code></em></span>
     <dd>

      <p class="para">
       The array to compare from
      </p>
     </dd>

    </dt>


    <dt>

     <span class="term"><em><code class="parameter">array2</code></em></span>
     <dd>

      <p class="para">
       An array to compare against
      </p>
     </dd>

    </dt>


    <dt>

     <span class="term"><em><code class="parameter">...</code></em></span>
     <dd>

      <p class="para">
       More arrays to compare against
      </p>
     </dd>

    </dt>


    <dt>

     <span class="term"><em><code class="parameter">key_compare_func</code></em></span>
     <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="type">int</span> <span class="methodname"><span class="replaceable">callback</span></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$a</code></span>, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$b</code></span> )</div>

     </dd>

    </dt>


   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-diff-uassoc-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an <span class="type"><a href="language.types.array.html" class="type array">array</a></span> containing all the entries from
   <em><code class="parameter">array1</code></em> that are not present in any of the other arrays.
  </p>
 </div>




 <div class="refsect1 examples" id="refsect1-function.array-diff-uassoc-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4940">
    <p><strong>Example #1  <span class="function"><strong>array_diff_uassoc()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     The <em>&quot;a&quot; =&gt; &quot;green&quot;</em>
     pair is present in both arrays and thus it is not in the output from the
     function. Unlike this, the pair <em>0 =&gt; &quot;red&quot;</em>
     is in the output because in the second argument <em>&quot;red&quot;</em>
     has key which is <em>1</em>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">key_compare_func</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">)?&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">:-</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$array1&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"a"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"brown"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"c"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"blue"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$array2&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"a"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"yellow"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_diff_uassoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$array1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"key_compare_func"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</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="cdata"><pre>
Array
(
    [b] =&gt; brown
    [c] =&gt; blue
    [0] =&gt; red
)
</pre></div>
    </div>
    <div class="example-contents"><p>
     The equality of 2 indices is checked by the user supplied callback function.
    </p></div>
   </div>
  </p>
 </div>
 

 <div class="refsect1 notes" id="refsect1-function.array-diff-uassoc-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    This function only checks one dimension of a n-dimensional
    array. Of course you can check deeper dimensions by using, for example,
    <em>array_diff_uassoc($array1[0], $array2[0], &quot;key_compare_func&quot;);</em>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-diff-uassoc-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.array-diff.html" class="function" rel="rdfs-seeAlso">array_diff()</a> - Computes the difference of arrays</span></li>
    <li class="member"> <span class="function"><a href="function.array-diff-assoc.html" class="function" rel="rdfs-seeAlso">array_diff_assoc()</a> - Computes the difference of arrays with additional index check</span></li>
    <li class="member"> <span class="function"><a href="function.array-udiff.html" class="function" rel="rdfs-seeAlso">array_udiff()</a> - Computes the difference of arrays by using a callback function for data comparison</span></li>
    <li class="member"> <span class="function"><a href="function.array-udiff-assoc.html" 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 class="member"> <span class="function"><a href="function.array-udiff-uassoc.html" 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 class="member"> <span class="function"><a href="function.array-intersect.html" class="function" rel="rdfs-seeAlso">array_intersect()</a> - Computes the intersection of arrays</span></li>
    <li class="member"> <span class="function"><a href="function.array-intersect-assoc.html" class="function" rel="rdfs-seeAlso">array_intersect_assoc()</a> - Computes the intersection of arrays with additional index check</span></li>
    <li class="member"> <span class="function"><a href="function.array-uintersect.html" class="function" rel="rdfs-seeAlso">array_uintersect()</a> - Computes the intersection of arrays, compares data by a callback function</span></li>
    <li class="member"> <span class="function"><a href="function.array-uintersect-assoc.html" class="function" rel="rdfs-seeAlso">array_uintersect_assoc()</a> - Computes the intersection of arrays with additional index check, compares data by a callback function</span></li>
    <li class="member"> <span class="function"><a href="function.array-uintersect-uassoc.html" class="function" rel="rdfs-seeAlso">array_uintersect_uassoc()</a> - Computes the intersection of arrays with additional index check, compares data and indexes by a callback functions</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-diff-key.html">array_diff_key</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-diff-ukey.html">array_diff_ukey</a></div>
 <div class="up"><a href="ref.array.html">Array Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>