Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 111

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>array_unique</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Array Functions"
HREF="ref.array.html"><LINK
REL="PREVIOUS"
TITLE="array_sum"
HREF="function.array-sum.html"><LINK
REL="NEXT"
TITLE="array_unshift"
HREF="function.array-unshift.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"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.array-sum.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.array-unshift.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.array-unique"
></A
>array_unique</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN8213"
></A
><P
>    (PHP 4 &#62;= 4.0.1)</P
>array_unique&nbsp;--&nbsp;Removes duplicate values from an array</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN8216"
></A
><H2
>Description</H2
>array <B
CLASS="methodname"
>array_unique</B
> ( array array)<BR
></BR
><P
>&#13;     <B
CLASS="function"
>array_unique()</B
> takes input
     <TT
CLASS="parameter"
><I
>array</I
></TT
> and returns a new array
     without duplicate values.
    </P
><P
>&#13;     Note that keys are preserved. <B
CLASS="function"
>array_unique()</B
> sorts
     the values treated as string at first, then will keep the first key
     encountered for every value, and ignore all following keys. It does not
     mean that the key of the first related value from the unsorted
     <TT
CLASS="parameter"
><I
>array</I
></TT
> will be kept.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </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
><P
>&#13;      The first element will be used.
     </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Warning</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;      This was broken in PHP 4.0.4!
      
     </P
></TD
></TR
></TABLE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN8237"
></A
><P
><B
>Example 1. <B
CLASS="function"
>array_unique()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$input = array ("a" =&#62; "green", "red", "b" =&#62; "green", "blue", "red");
$result = array_unique ($input);
print_r($result);</PRE
></TD
></TR
></TABLE
><P
>&#13;       This will output:
       <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>Array
(
    [b] =&#62; green
    [1] =&#62; blue
    [2] =&#62; red
)</PRE
></TD
></TR
></TABLE
>
      </P
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN8244"
></A
><P
><B
>Example 2. <B
CLASS="function"
>array_unique()</B
> and types</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$input = array (4,"4","3",4,3,"3");
$result = array_unique ($input);
var_dump($result);</PRE
></TD
></TR
></TABLE
><P
>&#13;       The printout of the program above will be (PHP 4.0.6):
       <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>array(2) {
  [3]=&#62;
  int(4)
  [4]=&#62;
  int(3)
}</PRE
></TD
></TR
></TABLE
>
      </P
></DIV
></TD
></TR
></TABLE
>
    </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-sum.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.array-unshift.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>array_sum</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.array.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>array_unshift</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>