|
|
|
Description
</H2
><DIV
CLASS="funcsynopsis"
><A
NAME="AEN4997"
></A
><P
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>array <B
CLASS="function"
>array</B
></CODE
> ([mixed
...])</CODE
></P
><P
></P
></DIV
><P
> Returns an array of the parameters. The parameters can be given
an index with the <TT
CLASS="literal"
>=></TT
> operator.
</P
><P
> <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
</P
></BLOCKQUOTE
></DIV
>
</P
><P
> Syntax "index => 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
> 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="AEN5012"
></A
><P
><B
>Example 1. <B
CLASS="function"
>Array()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> $fruits = array (
"fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"),
"numbers" => array (1, 2, 3, 4, 5, 6),
"holes" => array ("first", 5 => "second", "third")
);
</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
</P
><P
> <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN5017"
></A
><P
><B
>Example 2. Automatic index with <B
CLASS="function"
>Array()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> $array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13);
print_r($array);
</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
which will display :
<DIV
CLASS="informalexample"
><A
NAME="AEN5021"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 13
[4] => 1
[8] => 1
[9] => 19
)
</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
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
> 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="AEN5024"
></A
><P
><B
>Example 3. 1-based index with <B
CLASS="function"
>Array()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> $firstquarter = array(1 => 'January', 'February', 'March');
print_r($firstquarter);
</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
which will display :
<DIV
CLASS="informalexample"
><A
NAME="AEN5028"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> Array
(
[1] => 'January'
[2] => 'February'
[3] => 'March'
)
</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
</P
><P
>
See also : <A
HREF="get_example.php3?Function=list"
><B
CLASS="function"
>list()</B
></A
>.
|
|
| PHP Script to find url links in a page Categories : PHP, URLs, Regexps, Arrays | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Array values from javascript to php Categories : PHP, Java Script, Arrays | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | Array Insertion Categories : PHP, PHP Classes, Arrays | | | Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays | | | Single-file PHP news system with automatic folder structure creation Categories : PHP, Filesystem, Arrays | | | This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { } Categories : HTTP, Arrays, PHP | | | Beginners Array Functions Categories : PHP, Beginner Guides, Arrays | | | How to pass an array from one PHP Script to another via an HTML form Categories : PHP, HTML and PHP, Arrays | | | How to load a query result into a PHP Array Categories : PHP, Databases, Arrays, MySQL | | | dynamic table columns Categories : PHP, HTML and PHP, Arrays, Databases, MySQL | | | A recursive function to traverse a multi-dimensional array where the
dimensions are not known Categories : Arrays, PHP, Algorithms | |
| | | | ODeeN wrote : 10
why is this an 2 dimensional array
it seems to be an 3 dim
????????????????ß
| | | | Boaz Yahav wrote :11
Wel, lets see :
$fruits=>
array "a"=>"orange","b"=>"banana","c"=>"apple")
This is a one dimentional array right?
to print a value you would do :
print $fruits[a] and it would print orange
now if you do :
$fruits = array(
"fruits" => array("a"=>"orange","b"=>"banana","c"=>"apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);
This will be a two dimentional array.
To print a value you would do :
print $fruits[numbers][1]; to get 2
or
print $fruits[fruits][a]; to get orange
berber
| |
|
|
|