Advertisements
Advertisements
प्रश्न
Explain working of loops in array.
संक्षेप में उत्तर
Advertisements
उत्तर
Using Foreach loop:
- 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, the next element will be processed.
Example:
<?php
$Student_name = arrayO’Magilan”, “Iniyan”, “Nilani” “Sibi” “Shini”); foreach ($Student_name as $value) { echo “$value <br>”;
}
?>
Using For Loop:
To loop through and print all the values of an indexed array.
Example:
<?php$cars = arrayC’Volvo”, “BMW”, “Toyota”);
$arrlength = count(cars);
for($x = 0; $x < $arrlength; $x++){
echo $cars[$x];
echo “<br>”;
}
?>shaalaa.com
Looping Structure
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
APPEARS IN
संबंधित प्रश्न
The loop exclusively used for arrays is _____.
Loops that iterate for fixed number of times is called ______.
for ($ x=0; $ x<5; x++)
echo “Hai”
The above loop executes how many no of times?
What will be displayed in a browser when the following PHP code is executed;
<?php
for ($counter = 10; $counter < 10;
$counter = $counter + 5){
echo “Hello”;
}
?>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?
List out Looping Structure in PHP.
Write Syntax of For each loop in PHP.
Discuss in detail about Foreach loop.
Explain the process Do while loop.
