Wednesday, 10 August 2016

PHP Associative Array

An associative array is little bit different from regular array as in c and many language.

An array is a collection of similar data type which can be read by index

i.e. ar[8] here 8 is an index

In Associative array a key is used instead of index for getting array element. Key must be unique otherwise you can’t get all elements uniquely following code implement this logic

$ar=array("roll"=>"35","name"=>"Amit","fname"=>"Mr. Sumit","dob"=>"12-Aug-16");
echo "Roll : $ar[roll]<br>Name : $ar[name]<br> Father Name : $ar[fname]<br>Date of Birth : $ar[dob]";


Output : 
Roll : 35
Name : Amit
Father Name : Mr. Sumit
Date of Birth : 12-Aug-16

Next Topic

No comments:

Post a Comment