PHP - Associative Array

Associative array,each ID key is associated with a value.when storing data about specific named values,a numeric array is not always the best way to do it.with associative array we can use the values as keys and assign values to them.the following example of associative array.


<?php
	$age = array("john"=>21,"warner"=>25);
?>							
							

The following example is the same as example 1,but shows a different way of creating the array:


<?php
	$age['john'] = "21";
	$age['warner'] = "25";
?>							
							

The ID can be used in a following example.


<?php

	$age['john'] = "21";
	$age['warner'] = "25";
	echo "john age is ->".$age['john']."<br>;
	echo "warner age is ->".$age['warner']."<br>;
	
?>						
							

Output


john age is ->21
warner age is ->25							
							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!