An array is a variable which can store multiple values.

Each value is stored it its own array element.

Array elements are indexed so they can be easily referenced.

Numeric arrays

Numeric arrays have numeric indexes, starting with zero:

<?php
$city[0]='London';
$city[1]='Paris';
$city[2]='Tokyo';
print 'European cities: ' . $city[0] . ' and ' . $city[1];
?>

Numeric arrays in PHP use zero-based counting, which means you start with zero, not one. This can be a source of confusion.

Here is an alternate syntax:

$x=array('one','two','three');
print $x[0];  // Outputs "one"

Here is yet another syntax, using empty braces to automatically assign numeric indexes:

<?php
$city = array();
$city[]='London';  // empty squares braces create new array element
$city[]='Paris';   // each time we use [], we create the next element
$city[]='Tokyo';
print 'Japanese city: ' . $city[2];
?>

The above example is useful when your code adds an arbitrary number of elements which you don’t know in advance.

Associative arrays

Associative arrays use text indexes. Example:

<?php
$state['IA']='Iowa';
$state['MN']='Minnesota';
$state['WI']='Wisconsin';
print $state['MN'];  // outputs Minnesota
?>

Another way to make associative arrays:

<?php
$state = array ('IA'=>'Iowa', 'MN'=>'Minnesota', 'WI'=>'Wisconsin');
print $state['WI'];  // outputs Wisconsin
?>

The above example uses the array assignment operator: =>

See Also

http://www.w3schools.com/php/php_arrays.asp