PHP Associative Array

In an associative array, the keys assigned to values can be user defined strings. In the following example the array uses keys instead of index numbers:

<?php
 $array['index0'] = 'Apple';
 $array['index1'] = 'Mango';
 $array['index2'] = 'Banana';
 $array['index3'] = 'Apricot';
 $array['index4'] = 'Blackberry';
?>

Traversing PHP Associative Array

<?php
 foreach ($array as $key => $item) 
   {
     echo "$key = $item<br />";
   }
 ?>

Output:

index0 = Apple
index1 = Mango
index2 = Banana
index3 = Apricot
index4 = Blackberry