Home > PHP > PHP Array

PHP Array

ARRAY – An array stores multiple values in one single variable…

In PHP there are three kinds of ARRAY’s.They are,

1.Numeric Array (A numeric array stores each array element with a numeric index.)

2.Associative Array (An associative array, each ID key is associated with a value.)

3.Multidimensional Array (In a multidimensional array, each element in the main array can also be an array.

and each element in the sub-array can be an array, and so on.)

1.Numeric Array :

Two Methods.They are,

1.$fruits=array(“apple”,”orange”,”grapes”);

2.$fruits[0]=”apple” ;

$fruits[1]=”orange” ;

$fruits[2]=”grape”;

EXAMPLE :

<?php

$fruits=array(“apple”,”orange”,”grapes”);

echo $fruits[0].” and “.$fruits[1].” are very tasty ”

?>

2.Assosiative Array :

Two Methods.They are,

1.$ages=array(“vijayan”=>23,”pandian”=>18,”anand”=>23);

2.$ages[‘vijayan’]=”23″;

$ages[‘pandian’]=”18″;

$ages[‘anand’]=”23”;

EXAMPLE :

<?php

echo ” vijayan is “.$ages[‘vijayan’].” years old “;

?>

3.Multidimensional Array :

$family=array( “Parents”=>array(“a”,”b”) , “Brothers”=>array(“c”,”d”) , “Sisters”=>(“e”,”f”,”g”));

Example :

<?php

echo $family[‘parents’][1];

?>

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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: