An array in PHP is actually an ordered map. A map is a type that maps values to keys. This type is optimized in several ways, so you can use it as a real array, or a list (vector), hashtable (which is an implementation of a map), dictionary, collection, stack, queue and probably more. Because you can have another PHP array as a value, you can also quite easily simulate trees.
There are three different kind of arrays:
A numeric array stores each array element with a numeric index (ID Key).
There are different ways to create a numeric array.
1. In the following example the index are automatically assigned (the index starts at 0):
2. In the following example we assign the index manually:
PHP Example:-Use of ID key
In an associative array a key is associated with a value. If you wanted to store the prize of your products in an array, a numerically indexed array would not be the best choice. Instead, we could use the products names as the keys in our associative array, and the value would be their respective prize.PHP Example:-
As each element value of the array can be any type it means that it can be other array as well. If an array element value is an other array then this is a multidimensional array. Of course the internal array values can be arrays as well and so on. You can define 10 dimensional (or more) array if you want.
PHP Example :-
We create a multidimensional array, with automatically assigned ID keys:
?To err is human, but to really foul things up requires a computer.
?Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months.