250+ TOP PHP Coding MCQs on Print and Answers

PHP Multiple Choice Questions on “Print”.

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

  1. print "echo hello world";
  2. ?>

a) echo hello world
b) hello world
c) nothing
d) error
Answer: a
Clarification: The print statement will print whatever is present inside the double-quotes.

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

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

a) 01
b) 11
c) 10
d) Error
Answer: b
Clarification: Print can be used with or without parentheses.

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

  1. $cars = array("Volvo", "BMW", "Toyota");
  2. print $cars[2];
  3. ?>

a) Volvo
b) BMW
c) Toyota
d) Error
Answer: c
Clarification: Print statement can be used to output a specific array member.

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

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

a) onetwo
b) one
c) nothing
d) error
Answer: d
Clarification: The above syntax will produce an error, unlike the echo statement.

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

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

a) onetwo
b) one, two
c) one
d) error
Answer: d
Clarification: The above syntax will produce an error, unlike the echo statement.

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

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

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

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

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

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

a) true
b) false
c) nothing
d) error
Answer: c
Clarification: 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. $one = "one";
  2. $two = "one";
  3. print($one == $two);
  4. ?>

a) true
b) false
c) 1
d) error
Answer: c
Clarification: 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. print "Hello world!
    "
    ;
  2. print "I'm about to learn PHP!";
  3. ?>

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
Answer: c
Clarification: 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. print("this"."was"."a"."bad"."idea");
  2. ?>

a) thiswasabadidea
b) this was a bad idea
c) nothing
d) error
Answer: a
Clarification: You can use the dot operator like in echo but you can not use the comma operator to do the same.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top