Loops
1.
What will be the output of the following PHP code?
<?php
$i = 0;
for ($i)
{
print $i;
}
?>
2.
What will be the output of the following PHP code?
<?php
$colors = array("red","green","blue","yellow");
foreach ($colors as $value)
{
echo "$value <br>";
}
?>
3.
What will be the output of the following PHP code?
<?php
for ($x = 0; $x <= 10; $x++)
{
echo "The number is: $x <br>";
}
?>
4.
What will be the output of the following PHP code?
<?php
for ($x = 0; $x <= 10; print ++$x)
{
print ++$x;
}
?>
5.
What will be the output of the following PHP code?
<?php
for ($x = 1; $x < 10;++$x)
{
print "*\t";
}
?>
6.
What will be the output of the following PHP code?
<?php
for ($x = 1; $x < 10;++$x)
{
print "*\t";
}
?>
7.
What will be the output of the following PHP code?
<?php
for ($x = -1; $x < 10;--$x)
{
print $x;
}
?>
8.
What will be the output of the following PHP code?
<?php
$x;
for ($x = -3; $x < -5; ++$x)
{
print ++$x;
}
?>
9.
What will be the output of the following PHP code?
<?php
for ($i++; $i == 1; $i = 2)
print "In for loop ";
print "After loop\n";
?>
10.
What will be the output of the following PHP code?
<?php
for (1; $i == 1; $i = 2)
print "In for loop ";
print "After loop\n";
?>