Home Tutorial Php Phpbeginners Associative Arrays

 
 

Share on Google+Share on Google+
Associative Arrays
Posted on: February 5, 2011 at 12:00 AM
Advertisement
In this section,you will learn about the Associative Arrays of PHP.

Associative Arrays

In this section, you will learn about associative arrays and it 's implementation.

In an associative array, a key is associated with a value. We can use values as key and assign value to them.

Given below example will give you a clear idea :

Example

In the below example, we used an array named as "array" to assign ages to different persons. The key here is the name of the persons and we assign value to these keys.

<?php
$array=array("Ramesh"=>30,"Dinesh"=>32,"Mahesh"=>29,"Suresh"=>27);
$array["Vijay"]=34;
$array["Brijesh"]=26;
echo "Ramesh is ".$array["Ramesh"]." years old.</br>";
echo "Dinesh is ".$array["Dinesh"]." years old.</br>";
echo "Mahesh is ".$array["Mahesh"]." years old.</br>";
echo "Vijay is ".$array["Vijay"]." years old.</br>";
echo "Ramesh is ".$array["Ramesh"]." years old.</br>";
echo "Brijesh is ".$array["Brijesh"]." years old.</br>";

?>

Output

The output of the above example is given below :

Download Source Code

Advertisement

Related Tags for Associative Arrays:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 5, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com