In PHP array is a special variable which can used to store multiple values of same data type.

Array is used to hold all values under one single name and we used that value by referring that name of array. Array can be accessed by its index value.

Types of Array:

1.Numeric Array
2.Associative Array
3.Multidimensional Array.

Numeric Array:


In numeric array store each element with a numeric index. There are generally two methods to create a numeric array:


$computer = array("Acer","Lenovo","deal","hp");

In this the index value are automatically assigned to each array element starts from 0.

  1. b)$computer[0] = “Acer”;
  2. c)$computer[1] = “Lenovo”;
  3. d)$computer[2] = “deal”;
  4. e)$computer[3] = “hp”;

In this we assign the index value to each element in array.


$computer[0] =  "Acer";
$computer[1] = "Lenovo";
$computer[2] = "deal";
$computer[3] = "hp";

Echo $computer[0]."and".$computer[1]."are cheap and best";

Output: Acer and Lenovo are cheap and best.

Associative Array: 

In this each id is associative with a value. Numeric array is not best in storing data about specific named so we can use associative array. With associative array we can use the value as key and assign to them.

Example :

$employee = array (“Ram"=>23,"Sham"=>24,"Pankaj"=>23);


$employee ['Ram’] ="23";
$employee ['Sham’] = “24";
$employee ['Pankaj’] = “23";
<strong>Example :</strong>


$employee ['Ram’] ="23";
$employee ['Sham’] = “24";
$employee ['Pankaj’] = “23";

echo “Ram is".$employee['Ram’]."Year old";


Output: Ram is 23 year old.

Multidimensional Array.:


In this an array element contain array or we can say that each element in the main array can also be an array. And each element in the sub-array can be an array.


 array( array( Title => "laptop", 
                      Price => 75000,
                      Number => 15 
               array( Title => "Computer", 
                      Price => 25000,
                      Number => 25,
               array( Title => "Mouse", 
                      Price => 250,
                      Number => 7 
Pankaj Singh Sugara

Author Pankaj Singh Sugara

More posts by Pankaj Singh Sugara