PHP Loop MCQs
PHP Loop MCQs : This section focuses on "Loop" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. PHP supports ____ types of looping techniques?
View Answer
2. How many main parameter are used in for loop?
View Answer
3. do-while loop is an _____ control loop ?
View Answer
4. while loop is an _____ control loop ?
View Answer
5. foreach loop is used to iterate over ____?
View Answer
6. Which loop evaluates the condition expression as Boolean, if it is true, it executes the statements and when it is false it will terminate?
View Answer
7. What will be the output of the following PHP code?
<?php
for ($num = 1; $num <= 10; $num += 2) {
echo "$num ";
}
?>
View Answer
8. What will be the output of the following PHP code?
<?php
$num = 20;
while ($num < 12) {
$num += 2;
echo $num, "\n";
}
?>
View Answer
9. What will be the output of the following PHP code?
<?php
$num = 2;
do {
$num += 2;
echo $num, "\n";
} while ($num < 0);
?>
View Answer
10. What will be the output of the following PHP code?
<?php
$arr = array (10, 20, 30);
foreach ($arr as $val) {
echo "$val1 \n";
}
?>
View Answer
11. What will be the output of the following PHP code ?
<?php
do
{
print "LFC";
}
while(10);
print "I LOVE WEBSITE";
?>
View Answer
12. What will be the output of the following PHP code ?
<?php
$a;
for ($a = -3; $a < -5; ++$a)
{
print $x++;
}
?>
View Answer
13. What will be the output of the following PHP code ?
<?php
for ($a = 1; $a <= 10; $a++){
for ($b = 1; $b <= 5; $b++){
print "LFC
";
}
}
?>
View Answer
14. What will be the output of the following PHP code ?
<?php
for($num = 10; $num<=20; print ++$num)
{
print ++$num;
}
?>
View Answer
15. What will be the output of the following PHP code ?
<?php
$i=-5;
while($i){
$i++;
if($i%2==0)
continue;
else
{
$i++;
}
echo($i);
}
?>
View Answer
16. What will be the output of the following PHP code ?
<?php
for ($i = 0; $i < 4; $i++)
{
for ($j = 0; $j < 3; $j++)
{
if ($i > 1)
continue;
echo("Hi
");
}
}
?>
View Answer
17. What will be the output of the following PHP code ?
<?php
$i = 0;
$j = 0;
first: while ($i < 2)
{
$i++;
while ($j < 3)
{
$j++;
echo("loop
");
if($j%2==0)
continue;
goto first;
}
}
?>
View Answer
18. What will be the output of the following PHP code ?
<?php
for($i=0; $i<=5; $i++){
$i = $i+1;
}
echo "$i";
?>
View Answer
19. What will be the output of the following PHP code ?
<?php
$a = 10;
$b = $a>2?"Hi":"Bye";
echo "$b";
?>
View Answer
20. What will be the output of the following PHP code ?
<?php
$a = 0;
if($a > 1 );
{
echo "Sun";
}
echo "Moon";
?>
View Answer
Also check :
Discussion