Code: Select all
You can use the "foreach" statement to create a loop that allows you to work with each consecutive element in an array without having to specify each element's index. In the following example, each element in the $ vegetables array is assigned to the $value variable.Code: Select all
$vegetables = array ("broccoli", "carrot", "zucchini", "eggplant");
foreach ($vegetables as $value)
{
echo "The vegetable is: $value<br />\n";
}EDIT: ONE MORE QUESTION!
The book also says that if I want to access all of the varaibles in an array to type the following code:
Code: Select all
$paredes_family = array ("Frank Paredes", "Janice Paredes", "Brandon Paredes", "Jake Paredes");
for ($counter = 0; $counter < count($paredes_family); $counter++)
{
echo "$paredes_family[$counter]<br />\n";
}Code: Select all
$paredes_family = array ("Frank Paredes", "Janice Paredes", "Brandon Paredes", "Jake Paredes");
foreach ($paredes_family as $fam)
{
echo "$fam<br />\n";
}