Breaking

LightBlog

Saturday 4 July 2015

Associative Array in PHP


Associative Array are very similar to numeric array in term of functionality but they are different in terms of their index. Associative Array will have their index as string so that you can establish a strong association between key and values.
To store the salaries of employees in array, a numerically index array would not be best choice. We could use the employee name as the keys in our associative array, and the value would be their respective salary.
                                                      
Associative Array in PHP

For Example

<html>
<body>
<?php
$p1 = array ("Copier", "Inkjet", "Laser", "Photo");
echo "p1 element: " . $p1[2] . "<br>";
$p2 = array ('copier' => "Copier & Multipurpose",
'Inkjet' => "Inkjet Printer",
'Laser' => "Laser Printer",
'Photo' => "Photographic Paper");
echo "p2 element: " . $p2 ['inkjet']. "<br>";
?>
</body>
</html>

Another Example
<html>
<body>
<?php
$age=array("deep"=>22,"aman"=>23);
echo "deep age is ".$age['deep']."<br>"."aman age is ".$age['aman'];
?>
</body>
</html>

Here Video Provide
                                     
Adbox