WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : array -- Create an array
Categories : PHP, PHP Functions, Arrays Update Picture
documentation group PHP
Date : Apr 23rd 1999
Grade : 1 of 5 (graded 1 times)
Viewed : 6366
File : No file for this code example.
Images : No Images for this code example.
Search : More code by documentation group PHP
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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
>&#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
</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="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"
>&#13;$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="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"
>&#13;$array = array( 1, 1, 1, 1, 1, 8=&#62;1, 4=&#62;1, 19, 3=&#62;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"
>&#13;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
></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
>&#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="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"
>&#13; $firstquarter = array(1 =&#62; '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"
>&#13;Array
(
[1] =&#62; 'January'
[2] =&#62; 'February'
[3] =&#62; 'March'
)
</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
</P
><P
>&#13;

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