<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Array Operators</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Handleiding" HREF="index.html"><LINK REL="UP" TITLE="Operators" HREF="language.operators.html"><LINK REL="PREVIOUS" TITLE="String Operators" HREF="language.operators.string.html"><LINK REL="NEXT" TITLE="Type Operators" HREF="language.operators.type.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" 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" >PHP Handleiding</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="language.operators.string.html" ACCESSKEY="P" >Terug</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Hoofdstuk 10. Operators</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.operators.type.html" ACCESSKEY="N" >Volgende</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.operators.array" >Array Operators</A ></H1 ><DIV CLASS="table" ><A NAME="AEN3958" ></A ><P ><B >Tabel 10-7. Array Operators</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Example</TH ><TH >Name</TH ><TH >Result</TH ></TR ></THEAD ><TBODY ><TR ><TD >$a + $b</TD ><TD >Union</TD ><TD >Union of $a and $b.</TD ></TR ><TR ><TD >$a == $b</TD ><TD >Equality</TD ><TD ><TT CLASS="constant" ><B >TRUE</B ></TT > if $a and $b have the same elements.</TD ></TR ><TR ><TD >$a === $b</TD ><TD >Identity</TD ><TD ><TT CLASS="constant" ><B >TRUE</B ></TT > if $a and $b have the same elements in the same order.</TD ></TR ><TR ><TD >$a != $b</TD ><TD >Inequality</TD ><TD ><TT CLASS="constant" ><B >TRUE</B ></TT > if $a is not equal to $b.</TD ></TR ><TR ><TD >$a <> $b</TD ><TD >Inequality</TD ><TD ><TT CLASS="constant" ><B >TRUE</B ></TT > if $a is not equal to $b.</TD ></TR ><TR ><TD >$a !== $b</TD ><TD >Non-identity</TD ><TD ><TT CLASS="constant" ><B >TRUE</B ></TT > if $a is not identical to $b.</TD ></TR ></TBODY ></TABLE ></DIV ><P > The <VAR CLASS="literal" >+</VAR > operator appends the right handed array to the left handed, whereas duplicated keys are NOT overwritten. </P ><P > <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN3999" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$a </font><font color="#007700">= array(</font><font color="#DD0000">"a" </font><font color="#007700">=> </font><font color="#DD0000">"apple"</font><font color="#007700">, </font><font color="#DD0000">"b" </font><font color="#007700">=> </font><font color="#DD0000">"banana"</font><font color="#007700">);<br /></font><font color="#0000BB">$b </font><font color="#007700">= array(</font><font color="#DD0000">"a" </font><font color="#007700">=> </font><font color="#DD0000">"pear"</font><font color="#007700">, </font><font color="#DD0000">"b" </font><font color="#007700">=> </font><font color="#DD0000">"strawberry"</font><font color="#007700">, </font><font color="#DD0000">"c" </font><font color="#007700">=> </font><font color="#DD0000">"cherry"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$c </font><font color="#007700">= </font><font color="#0000BB">$a </font><font color="#007700">+ </font><font color="#0000BB">$b</font><font color="#007700">; </font><font color="#FF8000">// Union of $a and $b<br /></font><font color="#007700">echo </font><font color="#DD0000">"Union of \$a and \$b: \n"</font><font color="#007700">;<br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$c</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$c </font><font color="#007700">= </font><font color="#0000BB">$b </font><font color="#007700">+ </font><font color="#0000BB">$a</font><font color="#007700">; </font><font color="#FF8000">// Union of $b and $a<br /></font><font color="#007700">echo </font><font color="#DD0000">"Union of \$b and \$a: \n"</font><font color="#007700">;<br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$c</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > When executed, this script will print the following: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> Union of $a and $b:<br />array(3) {<br /> ["a"]=><br /> string(5) "apple"<br /> ["b"]=><br /> string(6) "banana"<br /> ["c"]=><br /> string(6) "cherry"<br />}<br />Union of $b and $a:<br />array(3) {<br /> ["a"]=><br /> string(4) "pear"<br /> ["b"]=><br /> string(10) "strawberry"<br /> ["c"]=><br /> string(6) "cherry"<br />}</font> </code></TD ></TR ></TABLE > </P ><P > Elements of arrays are equal for the comparison if they have the same key and value. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN4004" ></A ><P ><B >Voorbeeld 10-3. Comparing arrays</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$a </font><font color="#007700">= array(</font><font color="#DD0000">"apple"</font><font color="#007700">, </font><font color="#DD0000">"banana"</font><font color="#007700">);<br /></font><font color="#0000BB">$b </font><font color="#007700">= array(</font><font color="#0000BB">1 </font><font color="#007700">=> </font><font color="#DD0000">"banana"</font><font color="#007700">, </font><font color="#DD0000">"0" </font><font color="#007700">=> </font><font color="#DD0000">"apple"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$a </font><font color="#007700">== </font><font color="#0000BB">$b</font><font color="#007700">); </font><font color="#FF8000">// bool(true)<br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$a </font><font color="#007700">=== </font><font color="#0000BB">$b</font><font color="#007700">); </font><font color="#FF8000">// bool(false)<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also the manual sections on the <A HREF="language.types.array.html" >Array type</A > and <A HREF="ref.array.html" >Array functions</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="language.operators.string.html" ACCESSKEY="P" >Terug</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Begin</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="language.operators.type.html" ACCESSKEY="N" >Volgende</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >String Operators</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.operators.html" ACCESSKEY="U" >Omhoog</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Type Operators</TD ></TR ></TABLE ></DIV ></BODY ></HTML >