This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Echo”.
1. What will be the output of the following PHP code?
<?php
echo "Hello world </br> I am learning PHP";
?>
a) Hello world
b) Hello world I am learning PHP
c)
Hello world I am learning PHP
d) Error
View Answer
Explanation: The break tag is used as break line.
2. What will be the output of the following PHP code?
<?php
echo "Hello world <strong>I am learning PHP</strong>"
?>
a) Hello world
b) Hello world I am learning PHP
c)
Hello world I am learning PHP
d) Error
View Answer
Explanation: None.
3. What will be the output of the following PHP code?
<?php
echo "This", "was", "a", "bad", "idea";
?>
a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error
View Answer
Explanation: In an echo statement the comma operator is used to join strings.
4. What will be the output of the following PHP code?
<?php
echo "This"."was"."a"."bad"."idea";
?>
a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error
View Answer
Explanation: In an echo statement the dot operator is used to join strings.
5. What will be the output of the following PHP code?
<?php
echo "This","was"|"a","bad"."idea";
?>
a) Thiswasabadidea
b) Thiswasbadidea
c) Thiswas a badidea
d) Thiswas abadidea
View Answer
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?
<?php
$one = "Hello";
$two = "World";
echo $one, $two;
?>
a) Hello World
b) Hello
c) World
d) HelloWorld
View Answer
Explanation: Echo can print two variables which are separated by a comma.
7. What will be the output of the following PHP code?
<?php
$one = "Hello";
$two = "World";
echo "$one$two";
?>
a) HelloWorld
b) $one$two
c) Hello
d) Error
View Answer
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?
<?php
$one = "Hello";
$two = "World";
echo "$one"+"$two";
?>
a) HelloWorld
b) Hello+World
c) 0
d) Error
View Answer
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?
<?php
echo "This is <i>India</i>";
?>
a) This is India
b) This is India
c) This is
d) Error
View Answer
Explanation: None.
10. What will be the output of the following PHP code?
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "My car is a {$cars[0]}";
?>
a) My car is a Volvo
b) My car is a BMW
c) My car is a Toyota
d) Error
View Answer
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.
- Check Information Technology Books
- Apply for Programming Internship
- Check MCA Books
- Practice MCA MCQs
- Check PHP Books