Posts Tagged ‘Initializing an Associative Array’

Associative Arrays

Associative Arrays

In the products array, we allowed PHP to give each item the default index. This meant that the first item we added became item 0, the second item 1, and so on. PHP also supports associative arrays. In an associative array, we can associate any key or index we want with each value.

Initializing an Associative Array

The following code creates an associative array with product names as keys and prices as values.

$prices = array( 'Tires'=>100,
'Oil'=>10, 'Spark Plugs'=>4 );

Be the first to comment - What do you think?  Posted by admin - August 27, 2010 at 6:42 am

Categories: Array   Tags: ,