ExamVeda
Login
Home
41
What will be the output of the following PHP code ?
<?php
switch($b)
{
case 2:
    print "hello";
    break;
case 1:
    print "hi";
    break;
}
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
If that case does not exist then it searches for default and on not finding it does nothing.
42
What will be the output of the following PHP code ?
<?php
switch($b)
{
case 2:
    print "hello";
    break;
case b:
    print "hi";
    break;
}
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Case cannot be defined by a variable.
43
What will be the output of the following PHP code ?
<?php
while()
{
    print "hi";
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The while loop cannot be defined without a condition.
44
What will be the output of the following PHP code ?
<?php
do
{
    print "hi";
}
while(0);
print "hello";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The do while loop executes atleast once as the condition is in the while loop.
45
What will be the output of the following PHP code ?
<?php
$i = 0
while ($i < 3)
{
    $i++;
}
print $i;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The increment happens and then the check happens.
46
What will be the output of the following PHP code ?
<?php
$i = 0
do
{
    $i++;
}
while ($i < 3);
print $i;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The increment happens and then the check happens.
47
What will be the output of the following PHP code ?
<?php
$i = 0
while ($i++)
{
    print $i;
}
print $i;
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
As it is a post increment, it checks and then does not enter the loop, thus prints only 1.
48
What will be the output of the following PHP code ?
<?php
$i = "";
while($i)
{   
    print "hi";
}
print "hello";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
While accept does not accept anything other than a 0 or any other number as false and true.
49
What will be the output of the following PHP code ?
<?php
$i = "";
while ($i)
{   
    print "hi";
} 
while($i < 8)
    $i++;
print "hello";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The while loop ends only when a } is encountered.
50
What will be the output of the following PHP code ?
<?php
$i = 0;
while($i = 10)
{   
    print "hi";
}
print "hello";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
While condition always gives 1.