ExamVeda
Login
Home
51
What will be the output of the following PHP code ?
<?php
$i = "";
while ($i = 10)
{   
    print "hi";
}
print "hello";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
While condition always gives 1.
52
What will be the output of the following PHP code ?
<?php
$i = 5;
while (--$i > 0)
{   
    $i++; print $i; print "hello";
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
i is decremented in the first while execution and then continuously incremented back.
53
What will be the output of the following PHP code ?
<?php
$i = 5;
while (--$i > 0 && ++$i)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
As it is && operator it is being incremented and decremented continuously.
54
What will be the output of the following PHP code ?
<?php
$i = 5;
while (--$i > 0 || ++$i)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
As it is || operator the second expression is not evaluated till i becomes 1 then it goes into a loop.
55
What will be the output of the following PHP code ?
<?phpspan>
$i = 0;
while(?++$i || --$i)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
As it is || operator the second expression is not evaluated and i is always incremented, in the first case to 1.
56
What will be the output of the following PHP code ?
<?php
$i = 0;
while (++$i && --$i)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The first condition itself fails thus the loop exists.
57
What will be the output of the following PHP code ?
<?php
$i = 0;
while ((--$i > ++$i) - 1)
{   
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
(–$i > ++$i) evaluates to 0 but -1 makes it enters the loop and prints i.
58
What will be the output of the following PHP code ?
<?php
$i = 2;
while (++$i)
{   
    while ($i --> 0)
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The loop ends when i becomes 0.
59
What will be the output of the following PHP code ?
<?php
$i = 2;
while (++$i)
{   
    while (--$i > 0)
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The loop never ends as i is always incremented and then decremented.
60
What will be the output of the following PHP code ?
<?php
$i = 0;
for ($i)
{
    print $i;
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
Wrong syntax for for loop.