O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What Are Arrays?

The final variable type I’ll introduce in this book is the array. Unlike strings and numbers (which are scalar variables, meaning they can store only a single value at a time), an array can hold multiple, separate pieces of information. An array is therefore like a list of values, each value being a string or a number or even another array.

Arrays are structured as a series of key-value pairs, where one pair is an item or element of that array. For each item in the list, there is a key (or index) associated with it. The resulting structure is not unlike a spreadsheet or database table (Table 2.2).

Table 2.2. The $artists array uses numbers for its keys.
Array Example 1: $artists
KeyValue
0Low
1Aimee Mann
2Ani DiFranco
3Spiritualized ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required