# on 23-May-2015 (Sat)

#### Annotation 150891767

foreach is looping statement works only on arrays (and objects).

php 6
ough 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. <span>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.

#### Annotation 150891890

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

php 6
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). <span>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 w

On each pass through the loop, the $value variable gets set to the value of the current element status not read php 6 // (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. <span>On each pass through the loop, the $value variable gets set to the value of the current element. You can then do whatever you need to do with the value within the loop's code block. Then, the loop repeats again, getting the next value in the array, and so on. Here's an #### Annotation 150891903 Note that you can use any variable name you like to store the value. Essentially, any variable that you place after the as in the foreach statement gets assigned the current element's value. status not read php 6 ", "Tolkien", "Dickens" ); foreach ($authors as $val ) { echo$val . "
"; } This code displays: Steinbeck Kafka Tolkien Dickens Note that you can use any variable name you like to store the value. Essentially, any variable that you place after the as in the foreach statement gets assigned the current element's value. Try it yourself: Using foreach to Loop Through Values Using foreach to Lo

#### Annotation 150891907

When using foreach, the values you work with inside the loop are copies of the values in the array itself. This means that if you change the value given to you by foreach, you're not affecting the corresponding value in the original array.