Article 150891762php 6
6.4 Looping Through Arrays with foreach
As you just saw, it's easy to use each() in combination with while to loop through all the elements of an array. In fact, there's an even easier way: you can use PHP's foreach statement.
foreach is a special kind of looping statement that works only on arrays (and objects). You can use it in two ways. You can either retrieve just the value of each element, or you can retrieve the element's key and value.
Using foreach to Loop Through Values
The simplest way to use foreach is to retrieve each element's value, as follows:
foreach ( $array as $value )
// (do something with $value here)
// (rest of script here)
As you might imagine, the foreach loop continues to iterate until it has retrieved all the values in the array, from the first element to the last. On each pass through the loop, the $value variable gets set to the value of the current element. You can then do whateve