ExamVeda
Login
Home
11
What will be the output of the following PHP code ?
<?php
$color = "red";
$color = "green";
echo "$color";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The variable contains the last value which has been assigned.
12
What will be the output of the following PHP code ?
<?php
$color1 = "red";
$color2 = "green";
echo "$color1" . "$color2";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The . operator is used to join to strings.
13
What will be the output of the following PHP code ?
<?php
$color1 = "red";
$color2 = "green";
echo "$color1" + "$color2";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
+ operator does not join both the strings.
14
What will be the output of the following PHP code ?
<?php
$color1 = "red";
$color2 = "red";
echo "$color1" + "$color2";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
+ does not return 1 if the variables are equal.
15
What will be the output of the following PHP code ?
<?php
$color1 = "red";
$color2 = "1";
echo "$color1" + "$color2";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
+ just returns the numeric value even though it is inside double quotes.
16
What will be the output of the following PHP code ?
<?php
$color1 = "1";
$color2 = "1";
echo "$color1" + "$color2";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
+ can be used to add to integer values which are enclosed by double-quotes.
17
What will be the output of the following PHP code ?
<?php
$color1 = "red";
$color2 = "1";
$color3 = "grey"
echo "$color1" + "$color2" . "$color3";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
+ gives the value 1 and . is used to give join 1 and grey.
18
What will be the output of the following PHP code ?
<?php
echo "This", "was", "a", "bad", "idea";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
In an echo statement the comma operator is used to join strings.
19
What will be the output of the following PHP code ?
<?php
echo "This"."was"."a"."bad"."idea";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
In an echo statement the dot operator is used to join strings.
20
What will be the output of the following PHP code ?
<?php
echo "This","was"|"a","bad"."idea";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
You can use only comma and dot operator to join starings, other characters do not have the same function.