Array in php example

An array is a variable which contains multiple values, these values are indexed by numbers and strings.
We can assign values to an array in the following ways.
Method 1.
$city=array("Delhi","Mumbai","Chandigarh","Bangalore");
Method 2.
$city[]="Delhi";
$city[]="Mumbai";
$city[]="Chandigarh";
$city[]="Bangalore";
In above methods , Php automatically allot index number to values. Index starts from 0 onwords as 0,1,2,3...
We can give index to values manually too .
$city[0]="Delhi";
$city[1]="Mumbai";
$city[2]="Chandigarh";
$city[3]="Bangalore";
We access array values by referring index as given below.
print $city[0]." is the capital of India. And ". $city[2]." is union territory."
Result is
Delhi is capital of India. And Chandigarh is union territory.