PHP Coding Questions and Answers – Print

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Print”.

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

  1. <?php
  2. print "echo hello world";
  3. ?>

a) echo hello world
b) hello world
c) nothing
d) error
View Answer

Answer: a
Explanation: The print statement will print whatever is present inside the double-quotes.
advertisement
advertisement

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

  1. <?php
  2. $one = 1;
  3. print($one);
  4. print $one;
  5. ?>

a) 01
b) 11
c) 10
d) Error
View Answer

Answer: b
Explanation: Print can be used with or without parentheses.
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. $cars = array("Volvo", "BMW", "Toyota");
  3. print $cars[2];
  4. ?>

a) Volvo
b) BMW
c) Toyota
d) Error
View Answer

Answer: c
Explanation: Print statement can be used to output a specific array member.
advertisement

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

  1. <?php
  2. $one = "one";
  3. $two = "two";
  4. print($one$two);
  5. ?>

a) onetwo
b) one
c) nothing
d) error
View Answer

Answer: d
Explanation: The above syntax will produce an error, unlike the echo statement.

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

  1. <?php
  2. $one = "one";
  3. $two = "two";
  4. print($one,$two);
  5. ?>

a) onetwo
b) one, two
c) one
d) error
View Answer

Answer: d
Explanation: The above syntax will produce an error, unlike the echo statement.

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

  1. <?php
  2. $one = "one";
  3. $two = "two";
  4. print("$one$two");
  5. ?>

a) onetwo
b) $one$two
c) one
d) error
View Answer

Answer: a
Explanation: This is same as the echo statement.

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

  1. <?php
  2. $one = "one";
  3. $two = "two";
  4. print($one==$two);
  5. ?>

a) true
b) false
c) nothing
d) error
View Answer

Answer: c
Explanation: Since we are equating two unequal strings we do not get any output.

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

  1. <?php
  2. $one = "one";
  3. $two = "one";
  4. print($one == $two);
  5. ?>

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

Answer: c
Explanation: Since both the strings are equal the result 1 is printed on the screen.

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

  1. <?php
  2. print "Hello world!<br>";
  3. print "I'm about to learn PHP!";
  4. ?>

a) Hello world!
I’m about to learn PHP!
b) Hello world! I’m about to learn PHP!
c)

Hello world!
I'm about to learn PHP!

d) Error
View Answer

Answer: c
Explanation: Most of the properties of echo and print are same. Strings can contain HTML markup.

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

  1. <?php
  2. print("this"."was"."a"."bad"."idea");
  3. ?>

a) thiswasabadidea
b) this was a bad idea
c) nothing
d) error
View Answer

Answer: a
Explanation: You can use the dot operator like in echo but you can not use the comma operator to do the same.

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, 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]

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.