Associative Arrays

An associative array is a type of array where the key has its own value. In an associative array, we make use of key and value.


There are two ways to create an associative array: 

Example 1:

$age = array("Kailash"=>"27", "Ranjeet"=>"37", "Hemant"=>"43");
echo "Kailash is " . $age['Kailash'] . " years old.";



Kailash is 27 years old.


Example 2:


  echo "Kailash salary: ".$salary["Kailash"]."<br/>";  
  echo "Ranjeet salary: ".$salary["Ranjeet"]."<br/>";  
  echo "Hemant salary: ".$salary["Hemant"]."<br/>";  



Kailash salary: 350000
Ranjeet salary: 450000
Hemant salary: 200000