This set of Tough PHP Questions & Answers focuses on “Operators – 5”.
1. What will be the output of the following PHP code?
<?php
$i = 0; $j = 1; $k = 2;
print !(($i + $k) < ($j - $k));
?>
a) 1
b) true
c) false
d) 0
View Answer
Explanation: True is 1.
2. What will be the output of the following PHP code?
<?php
$i = 0;$j = 1;$k = 2;
print !(( + + $i + $j) > ($j - $k));
?>
a) 1
b) no output
c) error
d) 0
View Answer
Explanation: The equation outputs false .
3. What will be the output of the following PHP code?
<?php
$i = 0;$j = 1;$k = 2;
print (( + + $i + $j) >! ($j - $k));
?>
a) 1
b) no output
c) error
d) 0
View Answer
Explanation: Negation of a number is 0.
4. What will be the output of the following PHP code?
<?php
$a = 0x6db7;
print $a<<6;
?>
a) 1797568
b) no output
c) error
d) 0x6dc0
View Answer
Explanation: The output is in decimal.
5. What will be the output of the following PHP code?
<?php
$a = 'a' ;
print $a * 2;
?>
a) 192
b) 2
c) error
d) 0
View Answer
Explanation: Characters cannot be multiplied.
6. What will be the output of the following PHP code?
<?php
$a = '4' ;
print + + $a;
?>
a) no output
b) error
c) 5
d) 0
View Answer
Explanation: The character is type casted to integer before multiplying.
7. What will be the output of the following PHP code?
<?php
$a = '12345';
print "qwe{$a}rty";
?>
a) qwe12345rty
b) qwe{$a}rty
c) error
d) no output
View Answer
Explanation: {$}dereferences the variable within.
8. What will be the output of the following PHP code?
<?php
$a = '12345';
print "qwe".$a."rty";
?>
a) qwe12345rty
b) qwe$arty
c) error
d) no output
View Answer
Explanation: . dereferences the variable/string within.
9. What will be the output of the following PHP code?
<?php
$a = '12345';
echo 'qwe{$a}rty';
?>
a) qwe12345rty
b) qwe{$a}rty
c) error
d) no output
View Answer
Explanation: qwe{$a}rty, single quotes are not parsed.
10. What will be the output of the following PHP code?
<?php
$a = '12345';
echo "qwe$arty";
?>
a) qwe12345rty
b) qwe$arty
c) qwe
d) error
View Answer
Explanation: qwe, because $a became $arty, which is undefined.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all tough questions on PHP, here is complete set of 250 + Multiple Choice Questions and Answers on PHP.
- Practice MCA MCQs
- Check PHP Books
- Practice Programming MCQs
- Check Information Technology Books
- Apply for Programming Internship