Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Since we aren't indexing the array with integers, we can't just pull out each value starting
at zero. If you've turned ahead briefly to skim the array functions in Chapter 9, you may
have noticed functions like reset, next, and current. These functions offer one way to
step through an array, and they are the best way if you need to do more than simply step
through the array in order. You can also use the each function. However, PHP 4 added a
new statement called foreach specifically for stepping through an array. The foreach
statement is discussed in Chapter 3. It is like a for loop, but designed to pull elements
from an array. You may wish to turn back and review it.


Listing 5.3 Indexing Arrays with Strings

Free download pdf