Advertisements
Advertisements
प्रश्न
Discuss in detail about Foreach loop.
संक्षेप में उत्तर
Advertisements
उत्तर
- 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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
APPEARS IN
संबंधित प्रश्न
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”;
?>Consider the following code
<? php
$count=12;
do{
printf(“%d squared=%d<br/>”,
$count, pow($count,2));
} while($count<4);
?>
What will be the output of the code.
What will be the output of the following PHP code?
<?php
for ($x = 1; $x < 10;++$x)
{
print “*\t”;
}
?>What will be the output of the following PHP code?
<?php
for ($x = -1; $x < 10;--$x)
{
print $x;
}
?>Define for loop in PHP.
Write Syntax of For each loop in PHP.
Write Syntax of Do while loop in PHP.
Write the purpose of Looping Structure in PHP.
Explain working of loops in array.
