PHP Coding Questions and Answers – Operators – 5

This set of Tough PHP Questions & Answers focuses on “Operators – 5”.

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

  1. <?php
  2. $i = 0; $j = 1; $k = 2;
  3. print !(($i + $k) < ($j - $k));
  4. ?>

a) 1
b) true
c) false
d) 0
View Answer

Answer: a
Explanation: True is 1.
advertisement
advertisement

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

  1. <?php
  2. $i = 0;$j = 1;$k = 2;
  3. print !(( +  + $i + $j) > ($j - $k));
  4. ?>

a) 1
b) no output
c) error
d) 0
View Answer

Answer: b
Explanation: The equation outputs false .
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

advertisement
  1. <?php
  2. $i = 0;$j = 1;$k = 2;
  3. print (( +  + $i + $j) >! ($j - $k));
  4. ?>

a) 1
b) no output
c) error
d) 0
View Answer

Answer: a
Explanation: Negation of a number is 0.
advertisement

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

  1. <?php
  2. $a = 0x6db7;
  3. print $a<<6;
  4. ?>

a) 1797568
b) no output
c) error
d) 0x6dc0
View Answer

Answer: a
Explanation: The output is in decimal.

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

  1. <?php
  2. $a  =  'a' ;
  3. print $a * 2;
  4. ?>

a) 192
b) 2
c) error
d) 0
View Answer

Answer: d
Explanation: Characters cannot be multiplied.

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

  1. <?php
  2. $a  =  '4' ;
  3. print  +  + $a;
  4. ?>

a) no output
b) error
c) 5
d) 0
View Answer

Answer: c
Explanation: The character is type casted to integer before multiplying.

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

  1. <?php
  2. $a  =  '12345';
  3. print "qwe{$a}rty";
  4. ?>

a) qwe12345rty
b) qwe{$a}rty
c) error
d) no output
View Answer

Answer: a
Explanation: {$}dereferences the variable within.

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

  1. <?php
  2. $a  =  '12345';
  3. print "qwe".$a."rty";
  4. ?>

a) qwe12345rty
b) qwe$arty
c) error
d) no output
View Answer

Answer: a
Explanation: . dereferences the variable/string within.

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

  1. <?php
  2. $a  =  '12345';
  3. echo 'qwe{$a}rty';
  4. ?>

a) qwe12345rty
b) qwe{$a}rty
c) error
d) no output
View Answer

Answer: b
Explanation: qwe{$a}rty, single quotes are not parsed.

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

  1. <?php
  2. $a  =  '12345';
  3. echo "qwe$arty";
  4. ?>

a) qwe12345rty
b) qwe$arty
c) qwe
d) error
View Answer

Answer: c
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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.