This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Syntax – 2”.
1. What will be the output of the following PHP code?
<?php
/*
echo "Hello world";
*/
?>
a) Hello world
b) Nothing
c) Error
d)
/* Hello world */View Answer
Explanation: /* */ is used for commenting multiple lines.
2. What will be the output of the following PHP code?
<?php
$color = red;
echo "$color" . red ;
?>
a) red red
b) red
c) error
d) nothing
View Answer
Explanation: Use of undefined constant red.
3. What will be the output of the following PHP code?
<?php
$color1 = red;
$color2 = green;
echo "$color1"."$color2";
?>
a) red green
b) red
c) green
d) error
View Answer
Explanation: It has to be $color1 = “red”; and $color2 = “green”; therefore the error.
4. What will be the output of the following PHP code?
<?php
$color = "red";
$color = "green";
echo "$color";
?>
a) red
b) green
c) red green
d) error
View Answer
Explanation: The variable contains the last value which has been assigned.
5. What will be the output of the following PHP code?
<?php
$color1 = "red";
$color2 = "green";
echo "$color1" . "$color2";
?>
a) red
b) green
c) red green
d) redgreen
View Answer
Explanation: The . operator is used to join to strings.
6. What will be the output of the following PHP code?
<?php
$color1 = "red";
$color2 = "green";
echo "$color1" + "$color2";
?>
a) redgreen
b) red green
c) 0
d) error
View Answer
Explanation: + operator does not join both the strings.
7. What will be the output of the following PHP code?
<?php
$color1 = "red";
$color2 = "red";
echo "$color1" + "$color2";
?>
a) redgreen
b) red green
c) 0
d) 1
View Answer
Explanation: + does not return 1 if the variables are equal.
8. What will be the output of the following PHP code?
<?php
$color1 = "red";
$color2 = "1";
echo "$color1" + "$color2";
?>
a) red1
b) red 1
c) 0
d) 1
View Answer
Explanation: + just returns the numeric value even though it is inside double quotes.
9. What will be the output of the following PHP code?
<?php
$color1 = "1";
$color2 = "1";
echo "$color1" + "$color2";
?>
a) 11
b) 2
c) 0
d) 1
View Answer
Explanation: + can be used to add to integer values which are enclosed by double-quotes.
10. What will be the output of the following PHP code?
<?php
$color1 = "red";
$color2 = "1";
$color3 = "grey"
echo "$color1" + "$color2" . "$color3";
?>
a) 1grey
b) grey
c) 0
d) red1grey
View Answer
Explanation: + gives the value 1 and . is used to give join 1 and grey.
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 MCA Books
- Practice MCA MCQs
- Practice Programming MCQs
- Check PHP Books
- Check Information Technology Books