The array is very useful in storing like data. Arrays can also be sorted and searched.
What many programmers do not do is use an array along more than two axis.
The simplest form of an array is one with only one axis. It is nothing more than a long row of data.
int array[50];
Let's imagine now that we work in a large warehouse and our boss has tasked us with writing a simple program to inventory all of the items in the warehouse and where they are in the building.
In it's most basic sense, a one axis array is equivalent to a long line of boxes on the floor. This might work in a small warehouse but our building is quite large. We will look next at the two axis array, which is also the most common.
int array[50][50];
Now we have a two axis array. We can consider the first axis to be the row and the second axis to be the column.
We have gotten rid of the long snaking line along the floor and replaced it with a system of rows and columns to find where everything is but, everything is still on the floor!
The boss says he wants some shelving units in each row of the warehouse, but how do we account for this?
int array[50][50][10];
We have just moved on to the three axis array. Since we are already using the first two axis for row and column we will now use the third axis for shelf.
I'm only using ten shelves in the warehouse so I capped out that axis of the array at ten.
Now, if the boss wants to know where the rope is we can tell him it's in row 11, column 21 and shelf 3.
What's that? How do we store "rope" in an integer array? Well, we use product numbers to represent what an item is. The array does not store "rope" at array[11][21][3] but instead it holds the product ID code 7259 which means "rope."
"Well, that's all well and good," says the boss, "but, sometimes we sell out of something and put something new in the warehouse. I don't want to lose the fact that the shelf once held rope on it, how can we track that?"
Now we use a four dimensional array.
int array[50][50][10][50];
We now have an array that tracks: row, column, shelf and time. Our fourth dimension is one of time, it can be used to tell us what was once on that shelf.
Now, when the boss says, "Where's the rope," we can respond, "row 11, column 21 and shelf 3 (time=0)!"
If he then asks us what used to be there we can go back through the time element of the array and know what was once there.
You might be wondering why it is important to track what was once on a shelf? If you have ever worked in a warehouse you probably know that sometimes things get lost or someone misplaces something. If a report comes down that says we have one rope left, and we know where the rope used to be, there is a good chance we can go to where the rope used to be and find one near by.
If it helps think of arrays in the following way:
One element = straight line
Two elements = rectangle
Three elements = box
Four elements = a series of boxes in a straight line
You can go beyond four elements when creating arrays but you will likely not need to. In fact, if you were tracking the contents of a warehouse you would probably have a large array of pointers that point at objects which contain the information about the item in the warehouse.
You will likely never have a need to use anything bigger than a two dimensional array but I hope that this short exercise has enabled you to properly wrap your mind an array with more than two axis.