Advertisements
Advertisements
Question
Discuss in detail about Foreach loop.
Answer in Brief
Solution
- The foreach statement is used to loop through arrays.
- For each pass the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass next element will be processed.
Foreach loop Structure and Flow - Syntax:
foreach ($array as $value) { code to be executed; }
-
Example:
<?php $Student_name = a rrayÇ’MagiIan’ “Iniyan’ “NiIani’ “Sibi’ “Shini”); foreach ($Student_name as $value) { echo “$value <br>”; } ?>
shaalaa.com
Looping Structure
Is there an error in this question or solution?
APPEARS IN
RELATED QUESTIONS
Loops that iterate for fixed number of times is called ______.
Which loop evaluates condition expression as Boolean, if it is true, it executes statements and when it is false it will terminate?
What will be displayed in a browser when the following PHP code is executed:
<?php
for (Scounter = 20; $counter< 10;
$counter++)
{
echo “Welcome to Tamilnadu “;
}
echo “Counter is: Scounter”;
?>
PHP supports which types of looping techniques ______.
What will be the output of the following PHP code?
<?php
for ($x = -1; $x < 10;--$x)
{
print $x;
}
?>
What is For each loop in PHP?
Explain the use of for each loop in PHP.
Differentiate For each and While loop.
Explain the process Do while loop.
Explain working of loops in array.