250+ TOP PHP Coding MCQs on Operators and Answers

PHP Questions and Answers for Entrance exams on “Operators – 3”.

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

  1. echo 5 * 9 / 3 + 9;
  2. ?>

a) 24
b) 3.7
c) 3.85
d) 0
Answer: a
Clarification: Operator precedence order must be followed.

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

  1. echo 5 * 9 / 3 + 9
  2. ?>

a) 24
b) 3.7
c) 3.85
d) 0
Answer: a
Clarification: Operator precedence order must be followed.

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

  1. $i = 0;
  2. $j = 0;
  3. if ($i && ($j = $i + 10)) {
  4.     echo "true";
  5. }
  6. echo $j;
  7. ?>

a) 10
b) 0
c) true0
d) true10
Answer: b
Clarification: In if condition when the first case is 0 and is an && operation then the second command is not executed.

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

  1. $i = 10;
  2. $j = 0;
  3. if ($i || ($j = $i + 10)) {
  4.     echo "true";
  5. }
  6. echo $j;
  7. ?>

a) 20
b) true0
c) 0
d) true20
Answer: b
Clarification: In if condition when the first case is 1 and is an || operation then the second command is not executed.

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

  1. $i = 1;
  2. if ($i++ && ($i == 1))
  3.     printf("Yesn$i");
  4. else
  5.     printf("Non$i");
  6. ?>

a) No 2
b) Yes 1
c) Yes 2
d) No 1
Answer: a
Clarification: The first condition returns true and increments but the second condition is false.

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

  1. $a = 1; $b = 3;
  2. $d = $a++ + ++$b;
  3. echo $d;
  4. ?>

a) 5
b) 4
c) 3
d) error

Answer: a
Clarification: Post increment of a is done after expression evaluation.

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

  1. $a = 1; $b = 1; $d = 1;
  2. print ++$a + ++$a+$a++; print $a++ + ++$b; print ++$d + $d++ + $a++;
  3. ?>

a) 869
b) 742
c) 368
d) error
Answer: a
Clarification: Follow the order of post and pre increments.

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

  1. $a = 10; $b = 10;
  2. if ($a = 5)
  3.     $b--;
  4. print $a;print $b--;
  5. ?>

a) 58
b) 59
c) 109
d) 108
Answer: b
Clarification: a is set to 5 in the if condition and b is post decremented in the print statement.

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

  1. $i = 0;
  2. $x = $i++; $y = ++$i;
  3. print $x; print $y; 
  4. ?>

a) 02
b) 12
c) 01
d) 21
Answer: a
Clarification: First case i is incremented after setting x to i.

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

  1.  $a = 5; $b = -7; $c =0; 
  2.  $d = ++$a && ++$b || ++$c;
  3.  print $d; print $a;
  4. ?>

a) 16
b) 06
c) 15
d) 05
Answer: a
Clarification: 1&&0||1 is evaluated to 1 and the a is also preincremented to 6.

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

  1. $b = 1; $c = 4; $a = 5; 
  2. $d = $b + $c == $a;
  3. print $d;
  4. ?>

a) 5
b) 0
c) 10
d) 1
Answer: d
Clarification: First b and c are added and then tested if d=5, which is true thus return 1.

  250+ TOP MCQs on PHP File System and PHP and Answers

PHP for Entrance exams,

Leave a Comment

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

Scroll to Top