Operators And Expressions In Php - Study Mode

[#66] What will be the output of the following PHP code ? <?php $color1 = "red"
$color2 = "1"
echo "$color1" + "$color2"
?>
Correct Answer

(D) 1

Explanation

Solution: + just returns the numeric value even though it is inside double quotes.

[#67] What will be the output of the following PHP code ? <?php $color1 = "1"
$color2 = "1"
echo "$color1" + "$color2"
?>
Correct Answer

(B) 2

Explanation

Solution: + can be used to add to integer values which are enclosed by double-quotes.

[#68] What will be the output of the following PHP code ? <?php $color1 = "red"
$color2 = "1"
$color3 = "grey" echo "$color1" + "$color2" . "$color3"
?>
Correct Answer

(A) 1grey

Explanation

Solution: + gives the value 1 and . is used to give join 1 and grey.

[#69] What will be the output of the following PHP code ? <?php echo "This" , "was" , "a" , "bad" , "idea"
?>
Correct Answer

(C) Thiswasabadidea

Explanation

Solution: In an echo statement the comma operator is used to join strings.

[#70] What will be the output of the following PHP code ? <?php echo "This" . "was" . "a" . "bad" . "idea"
?>
Correct Answer

(C) Thiswasabadidea

Explanation

Solution: In an echo statement the dot operator is used to join strings.