PHP Print Associative Array Value



An associative array is another type of array where indexes are uniquely identified by a name. Here indexes are known as the key. During printing value, this key is used. One array can take only one unique key. The associate array can also be multidimensional. Below is an example of an associative array. Its needed to be printed


<?php
    $a = array(
      "day"         => "Wednesday",
      "date"        => "12-12-2018",
      "temperature" => 19,
      "humadity"    => "25%",
      "sunny"       => "yes"
    
    );
   
?>

For printing Wednesday as the value it needs to identify the key(index). For Wednesday key is "day". So, to print Wednesday code below is


<?php

   echo $a['day'];
?>

Result for $a['day'] is Wednesday


Wednesday

In the same way for printingĀ 12-12-2018 and yes its need to write code as well as below.


<?php

   echo $a['date']."
"; echo $a['sunny']."
"; ?>

Result for the code will be like that.


12-12-2018
yes

An associate array can also be multidimensional. To print multi-dimensional associative array generalĀ foreach loop is preferred. This is same as the general type of array.