Arrays

Arrays are one of our favorite parts of PHP because the syntax is smart and easy to read and yet manages to be as powerful as you could want. You need to know four pieces of jargon to understand arrays:

• An array is made up of many elements.

• Each element has a key that defines its place in the array. An array can have only one element with a given key.

• Each element also has a value, which is the data associated with the key.

• Each array has a cursor, which points to the current key.

The first three are used regularly; the last one less often. The array cursor is covered later in this chapter in the section “Basic Functions,” but we look at the other three now. With PHP, your keys can be almost anything: integers, strings, objects, ...

Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition 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.