O'Reilly logo

Core PHP Programming: Using PHP to Build Dynamic Web Sites by Leon Atkinson

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

The foreach Statement

I must discuss the foreach statement here, although it is used with arrays, which are discussed in Chapter 5. An array is a collection of values referenced by keys. The foreach statement retrieves values from an array, one at a time. Like other looping structures, the foreach statement may have a simple or compound statement that's executed each time through the loop. Figure 3-6 shows the structure of a foreach statement.

Figure 3-6. The foreach statement.

The foreach statement expects an array, the keyword as, and a definition of the variables to receive each element. If a single value follows as, such as foreach($array ...

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