This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “If-Else-If-2”.
1. What will be the output of the following PHP code?
<?php
$x = 10;
$y = 20;
if ($x > $y + $y != 3)
print "hi" ;
else
print "how are u";
?>
a) how are u
b) hi
c) error
d) no output
View Answer
Explanation: Expression evaluates to true.
2. What will be the output of the following PHP code?
<?php
$x = 10;
$y = 20;
if ($x > $y && 1||1)
print "hi" ;
else
print "how are u";
?>
a) how are u
b) hi
c) error
d) no output
View Answer
Explanation: Expression evaluates to true.
3. What will be the output of the following PHP code?
<?php
$x = 10;
$y = 20;
if ($x > $y && 1||1)
print "hi" ;
else
print "how are u";
?>
a) how are u
b) hi
c) error
d) no output
View Answer
Explanation: Expression evaluates to true.
4. What will be the output of the following PHP code?
<?php
if (-100)
print "hi" ;
else
print "how are u";
?>
a) how are u
b) hi
c) error
d) no output
View Answer
Explanation: Expression evaluates to true.
5. What will be the output of the following PHP code?
<?php
if (0.1)
print "hi" ;
else
print "how are u";
?>
a) how are u
b) hi
c) error
d) no output
View Answer
Explanation: Expression evaluates to true.
6. What will be the output of the following PHP code?
<?php
if (0.0)
print "hi" ;
else
print "how are u";
?>
a) how are u
b) hi
c) error
d) no output
View Answer
Explanation: Expression evaluates to false.
7. What will be the output of the following PHP code?
<?php
if (print "0")
print "hi" ;
else
print "how are u";
?>
a) 0how are u
b) 0hi
c) hi
d) how are u
View Answer
Explanation: Expression evaluates to true as print returns 1.
8. What will be the output of the following PHP code?
<?php
$x = 1;
if ($x == 2)
print "hi" ;
else if($x = 2)
print $x;
else
print "how are u";
?>
a) error
b) 2
c) hi
d) how are u
View Answer
Explanation: Enters if else as first condition is false and thus x is set to 2.
9. What will be the output of the following PHP code?
<?php
$x = 1;
if ($x = $x&0)
print $x ;
else
print "how are u";
?>
a) 0
b) 1
c) error
d) how are u
View Answer
Explanation: x&0 is 0,thus evaluated to false.
10. What will be the output of the following PHP code?
<?php
$x = 1;
if ($x = $x&0)
print $x ;
else
print "how are u";
?>
a) 0
b) 1
c) error
d) how are u
View Answer
Explanation: x&0 is 0,thus evaluated to false.
11. What will be the output of the following PHP code?
<?php
$x = 1;
if ($x = $x&0)
print $x;
else
break;
?>
a) 0
b) 1
c) error
d) no output
View Answer
Explanation: break is not defined for a if else ladder.
12. What will be the output of the following PHP code?
<?php
$a = 100;
if ($a > 10)
printf("M.S. Dhoni");
else if ($a > 20)
printf("M.E.K Hussey");
else if($a > 30)
printf("A.B. de villiers");
?>
a) M.S.Dhoni
b) M.E.K.Hussey
c)
M.S.Dhoni M.E.K.Hussey A.B.de villiers
d) No output
View Answer
Explanation: In if else if one condition is satisfied then no other condition is checked.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all areas of PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
- Check MCA Books
- Check PHP Books
- Practice MCA MCQs
- Apply for Programming Internship
- Check Information Technology Books