<HTML ><HEAD ><TITLE >array_diff</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual de PHP" HREF="index.html"><LINK REL="UP" TITLE="Funciones de matrices" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="array_diff_assoc" HREF="function.array-diff-assoc.html"><LINK REL="NEXT" TITLE="array_fill" HREF="function.array-fill.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual de PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.array-diff-assoc.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.array-fill.html" ACCESSKEY="N" >Siguiente</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.array-diff" ></A >array_diff</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN4814" ></A ><P > (PHP 4 >= 4.0.1)</P >array_diff -- Computes the difference of arrays</DIV ><DIV CLASS="refsect1" ><A NAME="AEN4817" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_diff</B > ( array array1, array array2 [, array ...])<BR ></BR ><P > <B CLASS="function" >array_diff()</B > returns an array containing all the values of <TT CLASS="parameter" ><I >array1</I ></TT > that are not present in any of the other arguments. Note that keys are preserved. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN4835" ></A ><P ><B >Ejemplo 1. <B CLASS="function" >array_diff()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array1 = array ("a" => "green", "red", "blue", "red"); $array2 = array ("b" => "green", "yellow", "red"); $result = array_diff ($array1, $array2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > This makes <TT CLASS="varname" >$result</TT > have <TT CLASS="literal" >array ("blue");</TT >. Multiple occurrences in $array1 are all treated the same way. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > Two elements are considered equal if and only if <TT CLASS="literal" >(string) $elem1 === (string) $elem2</TT >. In words: when the string representation is the same. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using <TT CLASS="literal" >array_diff($array1[0], $array2[0]);</TT >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Aviso</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > This was broken in PHP 4.0.4! </P ></TD ></TR ></TABLE ></DIV ><P > See also <A HREF="function.array-diff-assoc.html" ><B CLASS="function" >array_diff_assoc()</B ></A >, <A HREF="function.array-intersect.html" ><B CLASS="function" >array_intersect()</B ></A > and <A HREF="function.array-intersect-assoc.html" ><B CLASS="function" >array_intersect_assoc()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.array-diff-assoc.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Inicio</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.array-fill.html" ACCESSKEY="N" >Siguiente</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >array_diff_assoc</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" ACCESSKEY="U" >Subir</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >array_fill</TD ></TR ></TABLE ></DIV ></BODY ></HTML >