PHP Coding Questions and Answers – Echo

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

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

  1. <?php
  2. echo "Hello world </br> I am learning PHP";
  3. ?>

a) Hello world
b) Hello world I am learning PHP
c)

Hello world
I am learning PHP
advertisement
advertisement

d) Error
View Answer

Answer: c
Explanation: The break tag is used as break line.

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  1. <?php
  2. echo "Hello world <strong>I am learning PHP</strong>"
  3. ?>

a) Hello world
b) Hello world I am learning PHP
c)

Hello world
I am learning PHP
advertisement

d) Error
View Answer

Answer: b
Explanation: None.

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

advertisement
  1. <?php
  2. echo "This", "was", "a", "bad", "idea";
  3. ?>

a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error
View Answer

Answer: c
Explanation: In an echo statement the comma operator is used to join strings.

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

  1. <?php
  2. echo "This"."was"."a"."bad"."idea";
  3. ?>

a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error
View Answer

Answer: c
Explanation: In an echo statement the dot operator is used to join strings.

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

  1. <?php
  2. echo "This","was"|"a","bad"."idea";
  3. ?>

a) Thiswasabadidea
b) Thiswasbadidea
c) Thiswas a badidea
d) Thiswas abadidea
View Answer

Answer: b
Explanation: You can use only comma and dot operator to join starings, other characters do not have the same function.

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

  1. <?php
  2. $one = "Hello";
  3. $two = "World";
  4. echo $one, $two;
  5. ?>

a) Hello World
b) Hello
c) World
d) HelloWorld
View Answer

Answer: d
Explanation: Echo can print two variables which are separated by a comma.

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

  1. <?php
  2. $one = "Hello";
  3. $two = "World";
  4. echo "$one$two";
  5. ?>

a) HelloWorld
b) $one$two
c) Hello
d) Error
View Answer

Answer: a
Explanation: Even though both the variables are inside the double-quotes, the value of the variable is substituted and then printed to the screen.

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

  1. <?php
  2. $one = "Hello";
  3. $two = "World";
  4. echo "$one"+"$two";
  5. ?>

a) HelloWorld
b) Hello+World
c) 0
d) Error
View Answer

Answer: c
Explanation: In an echo statement you can not use plus sign to join two strings.

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

  1. <?php
  2. echo "This is <i>India</i>";
  3. ?>

a) This is India
b) This is India
c) This is
d) Error
View Answer

Answer: b
Explanation: None.

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

  1. <?php
  2. $cars = array("Volvo", "BMW", "Toyota");
  3. echo "My car is a {$cars[0]}";
  4. ?>

a) My car is a Volvo
b) My car is a BMW
c) My car is a Toyota
d) Error
View Answer

Answer: a
Explanation: In the echo statement the {$cars[0]} is replaced by the 1st element in cars that is Volvo.

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.