If I wanted to store all of my music artists and songs, I could create each one as a normal variable, which looks like this:
$artist1 = "Muse";
$song1 = "New Born";
$song2 = "Sunburn";
However, we could also store these in one variable - an array - which shall be named $music. Elements in an array have a unique key, which is essentially an address, so that the elements in the array can be accessed.
Because there will be several elements, we need to be able to access each one individually. An array will do this for you by numbering them, however, we can choose their names.
Now we'll create a basic array and put it to some use. Use the array() function to create an array and insert the elements:
$music = array ( "Muse", "New Born", "Sunburn" );
This keeps all of my music tastes inside an array $music and gives each element a key comprising of integers. In PHP this starts and 0 and increments by 1 for each element. Muse is element [0], New Born is [1] and Sunburn is [2].
You can access any of the array elements by the array name and the element number in square brackets, for example: $music[0]. Here it is in action:
<?php
echo "$music[1]"
?>
This will echo the second array element, "New Born". In PHP numbers start at zero (0), therefore, $music[1] is second.
You can also name each element individually when creating or adding to the array:
$music[] = "Muse";
$music[] = "New Born";
$music[] = "Sunburn";
This is the same as if you just used the array() function. Wow! What is that beautiful noise licking my ears!? It turns out I now have another favourite song. No problem, no matter what the size of the array is, I can simply add the new song to the array:
$music[] = "Uprising";
PHP is a clever chap and it will provide "Uprising" with the next available element in the array. Which is [3].