function.array-diff.html 7.18 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 die Unterschiede zwischen Arrays</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-diff-ukey.html">array_diff_ukey</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-fill-keys.html">array_fill_keys</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-diff" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_diff</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">array_diff</span> &mdash; <span class="dc-title">Ermittelt die Unterschiede zwischen Arrays</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.array-diff-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_diff</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>
  ] )</div>

  <p class="para rdfs-comment">
   Vergleicht <code class="parameter">array1</code> mit einem oder mehr anderen Arrays und
   gibt die Werte aus <code class="parameter">array1</code> zurück, die in keinem der 
   anderen Arrays enthalten sind.
  </p>
 </div>


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

    
     <dt>
<code class="parameter">array1</code></dt>

     <dd>

      <p class="para">
       Das Array, das verglichen werden soll
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">array2</code></dt>

     <dd>

      <p class="para">
       Das Array, mit dem verglichen werden soll
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">...</code></dt>

     <dd>

      <p class="para">
       Weitere Arrays, mit denen verglichen werden soll
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-diff-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt ein <span class="type"><a href="language.types.array.html" class="type Array">Array</a></span> mit allen Werten von
   <code class="parameter">array1</code> zurück, die in keinem der
   anderen Arrays vorhanden sind.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-diff-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-4901">
    <p><strong>Beispiel #1 <span class="function"><strong>array_diff()</strong></span>-Beispiel</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$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">"grün"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"rot"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"blau"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"rot"</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">"b"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"grün"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"gelb"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"rot"</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</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">);<br /><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>
     Wiederholte Elemente in <var class="varname"><var class="varname">$array1</var></var>
     werden alle gleich behandelt. Dies wird folgendes ausgeben:
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [1] =&gt; blau
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.array-diff-notes">
  <h3 class="title">Anmerkungen</h3>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Zwei Elemente werden nur dann als gleich angesehen, wenn
    <em>(string) $elem1 === (string) $elem2</em>. In Worten:
    Wenn die String-Repräsentation die gleiche ist.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Beachten Sie, dass diese Funktion nur eine Dimension eines n-dimensionalen
    Arrays prüft. Natürlich können Sie tiefere Dimensionen prüfen, indem Sie
    z.B. <em>array_diff($array1[0], $array2[0]);</em> benutzen.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-diff-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.array-diff-assoc.html" class="function" rel="rdfs-seeAlso">array_diff_assoc()</a> - Berechnet den Unterschied zwischen Arrays mit zus&auml;tzlicher
   Indexpr&uuml;fung</span></li>
    <li class="member"><span class="function"><a href="function.array-intersect.html" class="function" rel="rdfs-seeAlso">array_intersect()</a> - Ermittelt die Schnittmenge von 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> - Ermittelt die Schnittmenge von Arrays mit Indexpr&uuml;fung</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-ukey.html">array_diff_ukey</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-fill-keys.html">array_fill_keys</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>