Working with foreach LoopsThere's a special loop, the foreach loop, that makes working with complex variables such as arrays easier. We'll get the details on foreach in the next chapter, but we'll take a quick look at it here. Arrays store multiple data items, and this loop lets you loop over arrays without using a loop index. Here's how you use it:
You can see an example in phpforeach.php, Example 2-9, where foreach is looping over an array of fruits and echoing each to the browser window. Example 2-9. Using the foreach loop, phpforeach.php
The results appear in Figure 2-10; the loop was able to loop over all the items in the array automatically. The specifics of this loop are coming up in Chapter 3. Figure 2-10. Using the foreach loop.[View full size image] |
Friday, October 23, 2009
Working with foreach Loops
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment