PHP Array@ Shwetank

Definition – 
An array is a special variable ,
Which can store multiple values in one single variable

Numeric Array in php
A numeric array stores each array element with a numeric index. There are two methods to create a numeric array.

The index are Automatically assigned(the index start at 0)
$hello=array(“jai”, “Veeru”, “Gabbar”);

$car=array(“hello”, “Shwetank”);
echo “$car[1]”;

We assign the index manually
$jai[2]= “Hai”;

echo $sholey[1]. “and”. $sholey[3]. “Love”;

  An Associative Array in php
With associative array we can use the values as keys and assign values to them.


$ages= array(“jai”=>25, “Veeru”=>24, “bsanti”=>22);

echo “$ages[jai]”;

  Multidimensional Array in php
In a 2 D array , each element in the main array can also be an array .


$employees[“employee 1”][“name”] = “Herry”;
$employees[“employee 1”][“title”] = “Owner”;
$employees[“employee 1”][“salary”] = “$60,000”;

$employees[“employee 2”][“name”] = “Anisha Gupta”;
$employees[“employee 2”][“title”] = “Manager”;
$employees[“employee 2”][“salary”] = “$40,000”;

$employees[“employee 3”][“name”] = “Shwetank Kumar Gupta”;
$employees[“employee 3”][“title”] = “Cashier”;
$employees[“employee 3”][“salary”] = “$30,000”;

echo $employees[“employee 1”][“name”].
” is the “.$employees[“employee 1”][“title”].
” and she earns “.$employees[“employee 1”][“salary”].
” a year.”;

Try it Yourself