250+ TOP PHP Coding MCQs on If-Else-If-2 and Answers

PHP Question Bank on ” If-Else-If-2″.

1. What will be the output of the following PHP code?

  1. $x = 10;
  2. $y = 20;
  3. if ($x > $y + $y != 3)
  4.     print "hi" ;
  5. else
  6.     print "how are u";
  7. ?>

a) how are u
b) hi
c) error
d) no output
Answer: b
Clarification: Expression evaluates to true.

2. What will be the output of the following PHP code?

  1. $x = 10;
  2. $y = 20;
  3. if ($x > $y && 1||1)
  4.     print "hi" ;
  5. else
  6.     print "how are u";
  7. ?>

a) how are u
b) hi
c) error
d) no output
Answer: b
Clarification: Expression evaluates to true.

3. What will be the output of the following PHP code?

  1. $x = 10;
  2. $y = 20;
  3. if ($x > $y && 1||1)
  4.     print "hi" ;
  5. else
  6.     print "how are u";
  7. ?>

a) how are u
b) hi
c) error
d) no output
Answer: b
Clarification: Expression evaluates to true.

4. What will be the output of the following PHP code?

  1. if (-100)
  2.     print "hi" ;
  3. else
  4.     print "how are u";
  5. ?>

a) how are u
b) hi
c) error
d) no output
Answer: b
Clarification: Expression evaluates to true.

5. What will be the output of the following PHP code?

  1. if (0.1)
  2.     print "hi" ;
  3. else
  4.     print "how are u";
  5. ?>

a) how are u
b) hi
c) error
d) no output
Answer: b
Clarification: Expression evaluates to true.

6. What will be the output of the following PHP code?

  1. if (0.0)
  2.     print "hi" ;
  3. else
  4.     print "how are u";
  5. ?>

a) how are u
b) hi
c) error
d) no output

Answer: a
Clarification: Expression evaluates to false.

7. What will be the output of the following PHP code?

  1. if (print "0")
  2.     print "hi" ;
  3. else
  4.     print "how are u";
  5. ?>

a) 0how are u
b) 0hi
c) hi
d) how are u
Answer: b
Clarification: Expression evaluates to true as print returns 1.

8. What will be the output of the following PHP code?

  1. $x = 1;
  2. if ($x == 2)
  3.     print "hi" ;
  4. else if($x = 2)
  5.     print $x;
  6. else
  7.     print "how are u";
  8. ?>

a) error
b) 2
c) hi
d) how are u
Answer: b
Clarification: 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?

  1. $x = 1;
  2. if ($x = $x&0)
  3.     print $x ;
  4. else
  5.     print "how are u";
  6. ?>

a) 0
b) 1
c) error
d) how are u
Answer: d
Clarification: x&0 is 0,thus evaluated to false.

10. What will be the output of the following PHP code?

  1. $x = 1;
  2. if ($x = $x&0)
  3.     print $x ;
  4. else
  5.     print "how are u";
  6. ?>

a) 0
b) 1
c) error
d) how are u
Answer: d
Clarification: x&0 is 0,thus evaluated to false.

11. What will be the output of the following PHP code?

  1. $x = 1;
  2. if ($x = $x&0)
  3.     print $x;
  4. else
  5.     break;
  6. ?>

a) 0
b) 1
c) error
d) no output
Answer: c
Clarification: break is not defined for a if else ladder.

12. What will be the output of the following PHP code?

  1. $a = 100;
  2. if ($a > 10)
  3.     printf("M.S. Dhoni");
  4. else if ($a > 20)
  5.     printf("M.E.K Hussey");
  6. else if($a > 30)
  7.     printf("A.B. de villiers");
  8. ?>

a) M.S.Dhoni
b) M.E.K.Hussey
c)

M.S.Dhoni
M.E.K.Hussey
A.B.de villiers

d) No output

Answer: a
Clarification: In if else if one condition is satisfied then no other condition is checked.

To practice PHP Question Bank, here is complete set of 250 + Multiple Choice Questions and Answers on PHP .

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top