PHP For Loops
- What will be the output of the following PHP code ?
<?php
$name = array("Neha", "Sumi", "Abhay");
for (;count($name) < 5;)
{
if (count($name) == 3)
print $name;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Array to string conversion error.
- What will be the output of the following PHP code ?
<?php
$p = 0;
for(++$p; ++$p; ++$p)
{
print $p;
if ($p == 6)
break;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on.
- What will be the output of the following PHP code ?
<?php
for ($b = 0; $b = -5; $b = 1)
{
print $b;
if ($b != 2)
break;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on .
- What will be the output of the following PHP code ?
<?php
for(;;)
{
print "25";
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
There is no check condition to stop the execution of the loop.
- What will be the output of the following PHP code ?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Follow the trace of a, b prints 3 – a no of spaces for each a, b prints a stars for each loop.