foreach loops
Foreach loops were introduced in PHP 4. The foreach loop can only be used with arrays, they simply make it easier to iterate over elements in an array. There are two different ways to use the foreach loop, the second is just a useful addition to the first. Here's what a foreach loop looks like:
<?php
|
|
Using the first method, we can use the $value variable each time though the loop. This variable will contain the value of each array item. Using the second method, we can still use the $value variable, but now we can use the $key variable as well. The $key variable will contain the key of each array item.
Here is an example of how we can use each of these methods:
<?php
|
|
Give the example code above a try to see what happens, then go on to the next page to read about for loops.
| Discuss Tutorial: Using Loops in PHP | 4 Comments |
I used it for my birthday drop-down boxes 
!!
























