Creating a Array in PHP………

The array() language constructor is used to create an array in PHP.
Look at the syntax below:
array( [key =>] value
, …
// The key may be either an integer or a string
//The value is any reusable value
Let’s see how we can create an array by using the array() func-
$countries = array (“INDIA”, “PAKISTAN”, “JAPAN”)
Here we can access the second element by using
the index “1”. Let’s see:
echo “$country[1]”;
The output of this program is:
Now let’s see how we can create an array by using an array
$countries[] = “INDIA”;
$countries[] = “PAKISTAN”;
$countries[] = “JAPAN”;
Here, the values are inserted in the same order as the earlier
one. Using the index number, we can place the data as per our
requirement. You can insert these index numbers inside the
square brackets. Look at the following code:
$countries[1] = “PAKISTAN”;
$countries[2] = “JAPAN”;
$countries[0] = “INDIA”;
Example 1:
$learn = array(foo => “I am learning how to cre-
ate an array”, 12 => true);
echo $learn[foo]; // I am learning how to create
an array
echo $learn[12]; // Unit 01



About Dinesh

I am engineering student........ I am selected in Microsoft Student Partner as MSP............

Posted on December 6, 2010, in PHP. Bookmark the permalink. 1 Comment.

  1. Very enjoyable read but this weblog is kinda gradual to load and respond. Maybe you will have to improve your web hosting

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: