function.array-udiff-uassoc.html 14 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 mit zus&auml;tzlicher Indexpr&uuml;fung,
     vergleicht Daten und Indizes mittels einer Callbackfunktion</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-udiff-assoc.html">array_udiff_assoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-udiff.html">array_udiff</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-uassoc" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_udiff_uassoc</h1>
    <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">array_udiff_uassoc</span> &mdash; <span class="dc-title">Ermittelt den Unterschied zwischen Arrays mit zusätzlicher Indexprüfung,
     vergleicht Daten und Indizes mittels einer Callbackfunktion</span></p>

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

    <p class="para rdfs-comment">
     <span class="function"><strong>array_udiff_uassoc()</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 anders als von
     <span class="function"><a href="function.array-diff.html" class="function">array_diff()</a></span> und <span class="function"><a href="function.array-udiff.html" class="function">array_udiff()</a></span> für
     den Vergleich herangezogen werden. Der Vergleich der Arrayinhalte wird
     von der benutzerdefinierten Callbackfunktion 
     <code class="parameter">data_compare_func</code> durchgeführt. In dieser
     Hinsicht ist das Verhalten anders als jenes von
     <span class="function"><a href="function.array-diff-assoc.html" class="function">array_diff_assoc()</a></span>, welche eine eingebaute 
     Vergleichsfunktion verwendet. Der Vergleich der Schlüssel (Indizes) wird
     von der Funktion <code class="parameter">key_compare_func</code> durchgeführt.
     Dieses verhalten Unterschiedet sich von <span class="function"><a href="function.array-udiff-assoc.html" class="function">array_udiff_assoc()</a></span>
     darin, dass Letztere die Indizes mit einer eingebauten Funktion vergleicht.
    </p>
    <p class="para">
     <div class="example" id="example-4946">
      <p><strong>Beispiel #1 <span class="function"><strong>array_udiff_uassoc()</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 /><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 />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">comp_func_key</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&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">$b</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&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 />&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_uassoc</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">),&nbsp;array(</span><span style="color: #DD0000">"cr"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"comp_func_key"</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.1] =&gt; cr Object
        (
            [priv_member:private] =&gt; 9
        )

    [0.5] =&gt; cr Object
        (
            [priv_member:private] =&gt; 12
        )

    [0] =&gt; cr Object
        (
            [priv_member:private] =&gt; 23
        )
)
</pre></div>
      </div>
     </div>
    </p>
    <p class="simpara">
     In unserem Beispiel sehen Sie, dass das  <em>&quot;1&quot; =&gt; new cr(4)</em>
     Paar in beiden Arrays enthalten ist und daher nicht in der Ausgabe der
     Funktion auftaucht. Denken Sie daran, dass Sie zwei Callbackfunktionen
     angeben müssen.
    </p>
    <p class="simpara">
     Für den Vergleich wird die benutzerdefinierte Funktion verwendet.
     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. 
    </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_uassoc($array1[0], $array2[0], &quot;data_compare_func&quot;,
      &quot;key_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.html" class="function">array_udiff()</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-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-assoc.html">array_udiff_assoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-udiff.html">array_udiff</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>