Michelangelo van Dam has continued his introductory series looking at arrays in PHP with this latest post covering associative arrays (otherwise known as hash maps).
Associative array or hash maps are listings of key and value pairs with a possibility to nest additional keys and values. An associative array is a very powerful construct within PHP.
He mentions the previous article and its examples of numerically indexed arrays. He then shows how to use strings as the keys instead, pointing out that these are widely used in things like framework configurations. He shows how to use a foreach to work with the associative array and loop through each of the values, yielding the index and value for each. He also includes examples of for
and do-while
loops using the array_keys method to get the indexes before hand. He ends the post with a look at using the array_filter function to iterate over and find a certain record.