Sophie

Sophie

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

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

<HTML
><HEAD
><TITLE
>array</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_walk"
HREF="function.array-walk.html"><LINK
REL="NEXT"
TITLE="arsort"
HREF="function.arsort.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-walk.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.arsort.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.array"
></A
>array</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN8377"
></A
><P
>    (PHP 3, PHP 4 )</P
>array&nbsp;--&nbsp;
     Create an array
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN8380"
></A
><H2
>Description</H2
>array <B
CLASS="methodname"
>array</B
> ( [mixed ...])<BR
></BR
><P
>&#13;     Returns an array of the parameters.  The parameters can be given
     an index with the <TT
CLASS="literal"
>=&#62;</TT
> operator.
    </P
><P
>&#13;     <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
       <B
CLASS="function"
>array()</B
> is a language construct used to
       represent literal arrays, and not a regular function.
      </P
></BLOCKQUOTE
></DIV
>
    </P
><P
>&#13;     Syntax "index =&#62; values", separated by commas, define index
     and values. index may be of type string or numeric. When index is
     omitted, a integer index is automatically generated, starting
     at 0. If index is an integer, next generated index will
     be the biggest integer index + 1. Note that when two identical
     index are defined, the last overwrite the first.
    </P
><P
>&#13;     The following example demonstrates how to create a
     two-dimensional array, how to specify keys for associative
     arrays, and how to skip-and-continue numeric indices in normal
     arrays.
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN8396"
></A
><P
><B
>Example 1. <B
CLASS="function"
>array()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$fruits = array (
    "fruits"  =&#62; array ("a"=&#62;"orange", "b"=&#62;"banana", "c"=&#62;"apple"),
    "numbers" =&#62; array (1, 2, 3, 4, 5, 6),
    "holes"   =&#62; array ("first", 5 =&#62; "second", "third")
);</PRE
></TD
></TR
></TABLE
></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="AEN8401"
></A
><P
><B
>Example 2. Automatic index with <B
CLASS="function"
>array()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$array = array( 1, 1, 1, 1,  1, 8=&#62;1,  4=&#62;1, 19, 3=&#62;13);
print_r($array);</PRE
></TD
></TR
></TABLE
><P
>&#13;       will display :
       <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>Array
(
    [0] =&#62; 1
    [1] =&#62; 1
    [2] =&#62; 1
    [3] =&#62; 13
    [4] =&#62; 1
    [8] =&#62; 1
    [9] =&#62; 19
)</PRE
></TD
></TR
></TABLE
>
      </P
></DIV
></TD
></TR
></TABLE
>
     Note that index '3' is defined twice, and keep its final value of 13.
     Index 4 is defined after index 8, and next generated index (value 19)
     is 9, since biggest index was 8.
    </P
><P
>&#13;     This example creates a 1-based array.
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN8408"
></A
><P
><B
>Example 3. 1-based index with <B
CLASS="function"
>array()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$firstquarter  = array(1 =&#62; 'January', 'February', 'March');
print_r($firstquarter);</PRE
></TD
></TR
></TABLE
><P
>&#13;       will display :
       <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Array
(
    [1] =&#62; 'January'
    [2] =&#62; 'February'
    [3] =&#62; 'March'
)</PRE
></TD
></TR
></TABLE
>
      </P
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     See also <A
HREF="function.array-pad.html"
><B
CLASS="function"
>array_pad()</B
></A
>,
     <A
HREF="function.list.html"
><B
CLASS="function"
>list()</B
></A
>, and <A
HREF="function.range.html"
><B
CLASS="function"
>range()</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-walk.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.arsort.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>array_walk</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"
>arsort</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>