Associative Arrays


 

Associative Arrays

In this section,you will learn about the Associative Arrays of PHP.

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

Ads