What Is an Array?

You've already learned about and used scalar variables in this book, and you know that these variables are used to store values. But scalar variables can store only one value at a time. The $color variable can hold only a value of red or blue, and so forth—it cannot be used to hold a list of colors in the rainbow, for example. But arrays are special types of variables that enable you to store as many values as you want.

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. The value is whatever value you associate with that position—a string, an integer, or whatever you want. Think of an array as a filing cabinet and each key/value pair as a file folder. ...

Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.