This set of PHP Questions and Answers for Campus interviews focuses on “Operators – 4”.
1. What will be the output of the following PHP code?
<?php
echo 5 * 9 / 3 + 9;
?>
a) 24
b) 3.7
c) 3.85
d) 0
View Answer
Explanation: Operator precedence order must be followed.
2. What will be the output of the following PHP code?
<?php
$var1 = 1 + ++5;
echo $var1;
?>
a) no output
b) error
c) 6
d) 7
View Answer
Explanation: Operator ++ can be done only on variables.
3. What will be the output of the following PHP code?
<?php
$var1 = 0;
$var1 = ($var1 + 5)++;
echo $var1;
?>
a) 5
b) error
c) 6
d) 7
View Answer
Explanation: Operator ++ can be done only on variables.
4. What will be the output of the following PHP code?
<?php
$var1 = 0;
$var1 = $var1++ + 5;
echo $var1;
?>
a) 5
b) error
c) 6
d) 7
View Answer
Explanation: Operator precedence followed.
5. What will be the output of the following PHP code?
<?php
$var1 = 0;
$var1 = ++$var1 + 5;
echo $var1;
?>
a) 5
b) error
c) 6
d) 7
View Answer
Explanation: Operator precedence followed.
6. What will be the output of the following PHP code?
<?php
$var1 = 0;
$var1 = $var1 + 5;
echo $var1++;
?>
a) 5
b) error
c) 6
d) 7
View Answer
Explanation: Operator precedence followed,incremented after display.
7. What will be the output of the following PHP code?
<?php
$var1 = 1;
echo $var1 = ++$var1 % 2 + ++$var1;
?>
a) 1
b) 0
c) 2
d) 3
View Answer
Explanation: Evaluation done from right to left.
8. What will be the output of the following PHP code?
<?php
$a = 5;$b = -7;$c =0;
$d = ++$a && ++$b || ++$c;
print $d;print $a;
?>
a) 16
b) 06
c) 15
d) 05
View Answer
Explanation: 1&&0||1 is evaluated to 1 and the a is also pre incremented to 6.
9. What will be the output of the following PHP code?
<?php
$var1 = 3;
print $var = ++$var;
?>
a) 1
b) 0
c) 2
d) 3
View Answer
Explanation: $var = ++$var returns 1(success).
10. What will be the output of the following PHP code?
<?php
$var1 = 3;
print ++$var++;
?>
a) 3
b) 4
c) 5
d) error
View Answer
Explanation: First pre increment is done and the result is a number, thus post increment cannot be performed on it.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all areas of PHP for Campus Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Check PHP Books
- Practice MCA MCQs
- Practice Programming MCQs
- Apply for Programming Internship
- Check Information Technology Books