Home Tutorial Php Phpbeginners Associative Arrays

 
 

Associative Arrays
Posted on: February 5, 2011 at 12:00 AM
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

Related Tags for Associative Arrays:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.