A type of variable that can store multiple pieces of information and sort these pieces in a specified manner.

Arrays store values, sometimes alongside a key that identifies that value. Stroed values can be retrieved at another point, or be modified.

An array lets you add new items, delete items and rearrange the items inside it.

Think of a basic array – or indexed array – being like the following table:

0Jane Doe
1John Doe

Each row is a value stored within the array, the more items you add, the longer the array gets. Each value is assigned a number to identify it, starting at 0 and increasing by 1 for each new value. This number is known as an index.

In pseudo code you may write:

people = array("Jane Doe","John Doe");
print "My name is " . people[1];

Which would return “My name is John Doe”.

More complicated arrays, known as associative arrays, can use a specific name as a key for the values contained within it. Not all languages support this type of array e.g. Javascript.

To extend the example above, think of an associative array as the following table:

0Jane Doe32
1John Doe46

Each row is a value and key pair. This pair is still assigned an index, but you can retrieve a specific value by using the key. So, if we wanted Jane’s age (the value) we would ask the array for the value of key ‘Jane Doe’.

In pseudo code you may write:

age = array("Jane Doe"=>"32","John Doe"=>"46");
print "Jane Doe is age " . age["Jane Doe"];

Which would return “Jane Doe is age 32”.

Even more complicated than that are multidimensional arrays, which are arrays nested within other arrays. Not all languages support this type of array e.g. Javascript.

Index Value
Index Value
0 Jane Doe
1 Jack Doe
Index Value
0 John Doe
1 Jill Doe

In pseudo code you may write:

children = array(array("Jane Doe","Jack Doe"),array("John Doe","Jill Doe"));
print children[0][0] . " has a child called " . children[0][1];

Which would return “Jane Doe has a child called Jack Doe”.