What is an array? Arrays are common to almost every programming language. An array is simply an ordered map of values, indexed so you can find these values, called elements. These elements can be of multiple datatypes, and can be ordered any way you want.
Array ( [a] => 1 [b] => 2 [c] => 3 )
Two types of arrays in PHP There are two types of arrays in PHP, associative and enumerative. The difference between the two is how they are indexed.
Associative arrays allow you to index each element with an arbitrary value. For example, you can use letters of the alphabet, or just about anything to index the value, as long as it’s unique. Here is an example:
Some programmers prefer associative arrays because they can use the key to indicate what type of data is stored in the element, like “name” in the above example. This is an indicator of what is stored, however its not a rule that’s enforced. You can just as easily put a phone number in a name field and vice versa.
Enumerative arrays are indexed with a numerical index, either auto incremented, or random. PHP is very flexible with arrays, you can use numbers at will, and add in associative elements, and return to enumerative again. Also, the keys do not need to be sequential. Also note if you leave a key blank, an auto incremented number will be assigned to the key. Here is an example of an enumerative array: