This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Print”.
1. What will be the output of the following PHP code?
<?php
print "echo hello world";
?>
a) echo hello world
b) hello world
c) nothing
d) error
View Answer
Explanation: The print statement will print whatever is present inside the double-quotes.
2. What will be the output of the following PHP code?
<?php
$one = 1;
print($one);
print $one;
?>
a) 01
b) 11
c) 10
d) Error
View Answer
Explanation: Print can be used with or without parentheses.
3. What will be the output of the following PHP code?
<?php
$cars = array("Volvo", "BMW", "Toyota");
print $cars[2];
?>
a) Volvo
b) BMW
c) Toyota
d) Error
View Answer
Explanation: Print statement can be used to output a specific array member.
4. What will be the output of the following PHP code?
<?php
$one = "one";
$two = "two";
print($one$two);
?>
a) onetwo
b) one
c) nothing
d) error
View Answer
Explanation: The above syntax will produce an error, unlike the echo statement.
5. What will be the output of the following PHP code?
<?php
$one = "one";
$two = "two";
print($one,$two);
?>
a) onetwo
b) one, two
c) one
d) error
View Answer
Explanation: The above syntax will produce an error, unlike the echo statement.
6. What will be the output of the following PHP code?
<?php
$one = "one";
$two = "two";
print("$one$two");
?>
a) onetwo
b) $one$two
c) one
d) error
View Answer
Explanation: This is same as the echo statement.
7. What will be the output of the following PHP code?
<?php
$one = "one";
$two = "two";
print($one==$two);
?>
a) true
b) false
c) nothing
d) error
View Answer
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?
<?php
$one = "one";
$two = "one";
print($one == $two);
?>
a) true
b) false
c) 1
d) error
View Answer
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?
<?php
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
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
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?
<?php
print("this"."was"."a"."bad"."idea");
?>
a) thiswasabadidea
b) this was a bad idea
c) nothing
d) error
View Answer
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]
- Check PHP Books
- Check Information Technology Books
- Check MCA Books
- Practice Programming MCQs
- Apply for Programming Internship