function.array-udiff.html 11.3 KB
<!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>Ermittelt den Unterschied zwischen Arrays mittels einer Callbackfunktion f&uuml;r den Datenvergleich</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-udiff-uassoc.html">array_udiff_uassoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-uintersect-assoc.html">array_uintersect_assoc</a></div>
 <div class="up"><a href="ref.array.html">Array Funktionen</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-udiff" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_udiff</h1>
    <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">array_udiff</span> &mdash; <span class="dc-title">
     Ermittelt den Unterschied zwischen Arrays mittels einer Callbackfunktion für den Datenvergleich
    </span></p>

   </div>
   <div class="refsect1 description" id="refsect1-function.array-udiff-description">
    <h3 class="title">Beschreibung</h3>
     <div class="methodsynopsis dc-description">
      <span class="type">array</span> <span class="methodname"><strong>array_udiff</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.pseudo-types.html#language.types.callback" class="type callback">callback</a></span> <code class="parameter">$data_compare_func</code></span>
      )</div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_udiff()</strong></span> gibt ein Array mit allen Werten von
     <code class="parameter">array1</code>, welche in keinem der anderen Argumente
     enthalten sind, zurück. Beachten Sie, dass Schlüssel erhalten bleiben.
     Für den Vergleich der Daten wird <code class="parameter">data_compare_func</code>
     herangezogen. Diese muss einen Integer kleiner als, genau gleich oder
     größer als Null zurückgeben, wenn das erste Argument entsprechend als
     kleiner, gleich oder größer als das Zweite betrachtet wird. Dies ist anders
     als <span class="function"><a href="function.array-diff.html" class="function">array_diff()</a></span>, in der eine eingebaute Funktion
     für den Vergleich der Indizes verwendet wird.
    </p>
    <p class="para">
     <div class="example" id="example-4947">
      <p><strong>Beispiel #1 <span class="function"><strong>array_udiff()</strong></span> Beispiel</strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">cr&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;</span><span style="color: #0000BB">$priv_member</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">priv_member&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">comp_func_cr</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">)&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$a</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">priv_member&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">priv_member</span><span style="color: #007700">)&nbsp;return&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(</span><span style="color: #0000BB">$a</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">priv_member&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">priv_member</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 />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"0.1"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">9</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"0.5"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">12</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">23</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">2&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(-</span><span style="color: #0000BB">15</span><span style="color: #007700">),);<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"0.2"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">9</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"0.5"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">22</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">2&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">cr</span><span style="color: #007700">(-</span><span style="color: #0000BB">15</span><span style="color: #007700">),);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_udiff</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">,&nbsp;array(</span><span style="color: #DD0000">"cr"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"comp_func_cr"</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>Das oben gezeigte Beispiel erzeugt folgende
Ausgabe:</p></div>
      <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0.5] =&gt; cr Object
        (
            [priv_member:private] =&gt; 12
        )

    [0] =&gt; cr Object
        (
            [priv_member:private] =&gt; 23
        )

)
</pre></div>
      </div>
     </div>
    </p>
    <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
     <span class="simpara">
      Bitte beachten Sie, dass diese Funktion nur eine Dimension eines
      n-dimensionalen Arrays überprüft. Natürlich können Sie tiefere Dimensionen
      prüfen, indem Sie
      <em>array_udiff($array1[0], $array2[0], &quot;data_compare_func&quot;);</em>
      verwenden.
     </span>
    </p></blockquote>
    <p class="para">
     Siehe auch
     <span class="function"><a href="function.array-diff.html" class="function">array_diff()</a></span>,
     <span class="function"><a href="function.array-diff-assoc.html" class="function">array_diff_assoc()</a></span>,
     <span class="function"><a href="function.array-diff-uassoc.html" class="function">array_diff_uassoc()</a></span>,
     <span class="function"><a href="function.array-udiff-assoc.html" class="function">array_udiff_assoc()</a></span>, 
     <span class="function"><a href="function.array-udiff-uassoc.html" class="function">array_udiff_uassoc()</a></span>, 
     <span class="function"><a href="function.array-intersect.html" class="function">array_intersect()</a></span>,  
     <span class="function"><a href="function.array-intersect-assoc.html" class="function">array_intersect_assoc()</a></span>,
     <span class="function"><a href="function.array-uintersect.html" class="function">array_uintersect()</a></span>,  
     <span class="function"><a href="function.array-uintersect-assoc.html" class="function">array_uintersect_assoc()</a></span> und 
     <span class="function"><a href="function.array-uintersect-uassoc.html" class="function">array_uintersect_uassoc()</a></span>.
    </p>
   </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-udiff-uassoc.html">array_udiff_uassoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-uintersect-assoc.html">array_uintersect_assoc</a></div>
 <div class="up"><a href="ref.array.html">Array Funktionen</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>