Arrays in PHP

Welcome to the world of Arrays! In this tutorial we will learn more about PHP arrays, types of Arrays, how to store and retrieve data from arrays with the help of examples and explanation.

What is an Array?

An array is a like a list or a group of similar elements which stores data of a specific data type. These data elements are stored in a series inside the array and each of these stored data element has its own position in the Array by which it is referred to and retrieved. The position of these stored elements is maintained by the Index of the Array which is usually made up of consecutive integers beginning at zero. The values which are used to index the elements in an array are unique. That means, you can have only one unique value as an indexer (Key) and no two data elements in an array will have same indexer or the key.

See this example:

Name
John
Greg
Romeo
David
Chris

The above list consists of names of individuals. Note that the position of the first name is starting with zero. Let's see another example of a list.

Protocols
TCP
IP
FTP
SMTP
POP3
DNS

That was a list of some of the protocols which are most widely used on Internet. Note that the position of the first protocol 'TCP' in the list is zero.

Since you now have an understanding of the basics of arrays, let's move onto the next topic Types of Arrays in PHP.

Further reading on Arrays in PHP