#associativeArray [[Outcome 1 - Programming#5. characteristics of data structures, including]] An associative array is essentially a way of connecting two pieces of information together. It will not be the main repository for the data within a system, but will instead aid in the organisation of that data by associating a transaction or event to it. The way that it does this is by using the main key value used to index the data and then connecting it to another value to form a (key, value) pair. Key values do not have to be all represented in the associative array, but by definition, should be unique identifiers. ![[Pasted image 20251216133342.png]] Let's say that we need to record the names of people that are staying in a hotel (by the room number). If a person is staying in a room, then we record their name against the room number, otherwise we don't record the room number in our array at all. An associative array to represent this might look like the one below. There are a few things to note about associative arrays that are illustrated by this example. | Key | Value | | --- | -------- | | 101 | "Elaine" | | 105 | "Mike" | | 106 | "Judy" | | 204 | "Lee" | Firstly, an association consists of a binding and this is often shown by using a ':'. Some programming languages actually make use of the ':' character in their implementation of associative arrays. The second thing to note is that not all of the rooms in the hotel are represented. In fact, it is not clear how many rooms are present in the hotel. The third thing to note is that a person can effectively book more than one hotel room under their name. The 'key' cannot be repeated but the 'value' can be.