What is an Array?
You've already learned about and used scalar variables in the earlier chapters in this book, and thus you know that these variables are used to store values. But scalar variables can store only one value at a timethe $color variable can hold only a value of red or blue, and so forth, but it cannot be used to hold a list of colors in the rainbow. But arrays are special types of variables that enable you to store as many values as you want, including all seven of those rainbow colors.
Arrays are indexed, which means that each entry is made up of a key and a value. The key is the index position, beginning with 0 and increasing incrementally by one with each new element in the array. The value is whatever value you associate with that positiona string, an integer, or whatever you want. Think of an array as a filing cabinet and each key/value pair as a file folder. The key is the label written on the top of the folder, and the value is what is inside. You'll see this type of structure in action, as you create arrays in the next section.
|