Whenever we need to store the key-value pairs, we can use Associative Array in PHP. Moreover, when the index is not an integer we can’t use the indexed array. Similarly, in case, index doesn’t start with 0, then also it is not possible to use the ordinary indexed array. In all such cases, we can use an associative array. The following code shows an example of Associative Array in PHP.

$arr=array(50=>250, 12=>60, -8=>-40, 'abc'=>77, 'p'=>'xyz');
echo '<br>Elements of associative array displayed using foreach 

foreach($arr as $k)
	echo $k.'<br>';


Creating Associative Array in PHP
Creating Associative Array in PHP

Further Reading

Examples of Array Functions in PHP

Basic Programs in PHP

Registration Form Using PDO in PHP