submitted by: Guest
PHP: foreach loop
simple php example of a for-each loop, useful for iterating over lists and objects arrays.
code snippet:
<?php
// foreach example - loop through each entry in an array
$metals = array("copper","iron","gold","cobalt");
foreach ( $metals as $element ) {
echo "This element is: $element<BR>";
}
?>
sample output:
This element is: copper
This element is: iron
This element is: gold
This element is: cobalt
This element is: iron
This element is: gold
This element is: cobalt



