IMPRESS dotted_line CONTACT dotted_line search dotted_line Kontakt dotted_line sitemap dotted_line print
172 PHP-Resource users online

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PHP 4 >= 4.0.1, PHP 5)

array_diffComputes the difference of arrays


array array_diff ( array $array1 , array $array2 [, array $... ] )

Compares array1 against array2 and returns the difference.



The array to compare from


An array to compare against


More arrays to compare against

Return Values

Returns an array containing all the entries from array1 that are not present in any of the other arrays.


Example #1 array_diff() example

= array("a" => "green""red""blue""red");
$array2 = array("b" => "green""yellow""red");
$result array_diff($array1$array2);


Multiple occurrences in $array1 are all treated the same way. This will output :

    [1] => blue



Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.


This function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_diff($array1[0], $array2[0]);.

See Also

Comments to the PHP manual
Write new comment


New Tutorial entries

Migration einer PHP 5 App auf PHP 7

Dieses PHP 7 Tutorial zeigt dir, wie du dein PHP5 Script auf PHP7 umstellst.

Berni | Category: PHP
PHP 7 Virtual Machine

Dieser Artikel zielt darauf ab, einen Überblick über die Zend Virtual Machine, wie es in PHP 7 gefunden wird.

Berni | Category: PHP
plotting masters - a professional guide - Teil II

Grafische Interpolation und Bestapproximation von numerischen Wertepaaren: Wir wollen Punkte auf einer Zeichenebene über verschiedene Verfahren miteinander verbinden.

EVAMasters | Category: PHP