0
0
PHPprogramming~5 mins

String concatenation operator in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the string concatenation operator in PHP?
The string concatenation operator in PHP is the dot (.) symbol. It joins two or more strings together.
Click to reveal answer
beginner
How do you join the strings "Hello" and "World" in PHP?
You use the concatenation operator like this: $greeting = "Hello" . " " . "World"; which results in "Hello World".
Click to reveal answer
beginner
What will be the output of this PHP code?<br>
$a = "Good";<br>$b = "Morning";<br>echo $a . " " . $b;
The output will be: Good Morning. The dot operator joins the strings and the space " " adds a space between them.
Click to reveal answer
beginner
Can you use the plus (+) operator to concatenate strings in PHP?
No, the plus (+) operator is for numbers only. Using it with strings will cause errors or unexpected results. Use the dot (.) operator for strings.
Click to reveal answer
beginner
How to concatenate multiple strings in PHP in one statement?
You can chain the dot operator like this:<br>$full = "I" . " " . "love" . " " . "PHP";<br>This results in "I love PHP".
Click to reveal answer
Which operator is used to join strings in PHP?
A- (minus)
B+ (plus)
C& (ampersand)
D. (dot)
What will this PHP code output?<br>
echo "Hi" . " " . "there!";
AHi+there!
BHi there!
CHiThere!
DError
What happens if you use + to join strings in PHP?
AIt concatenates strings
BIt converts strings to uppercase
CIt adds numbers only, strings cause error or unexpected results
DIt repeats the string
How to add a space between two concatenated strings in PHP?
AUse a space inside one string or concatenate a space string like " "
BUse + operator
CUse a comma between strings
DUse a semicolon
Which of these is a valid PHP string concatenation?
A$x = "a" . "b" . "c";
B$x = "a" + "b" + "c";
C$x = "a" & "b" & "c";
D$x = "a" - "b" - "c";
Explain how to join two strings in PHP and how to include a space between them.
Think about the symbol used to join strings and how to add spaces.
You got /4 concepts.
    Describe why the plus (+) operator is not used for string concatenation in PHP.
    Consider the difference between numbers and strings in PHP operators.
    You got /3 concepts.