Recall & Review
beginner
What does the assignment operator
= do in PHP?It assigns the value on the right side to the variable on the left side. For example,
$a = 5; sets the variable $a to 5.Click to reveal answer
beginner
What is a compound assignment operator?
A compound assignment operator combines an operation with assignment. For example,
$a += 3; adds 3 to $a and then assigns the result back to $a.Click to reveal answer
beginner
List three common compound assignment operators in PHP.
1.
+= (addition assignment)<br>2. -= (subtraction assignment)<br>3. *= (multiplication assignment)Click to reveal answer
beginner
What happens when you write
$x *= 2; if $x is 4?The value of
$x becomes 8 because it multiplies the current value (4) by 2 and assigns the result back to $x.Click to reveal answer
beginner
Can compound assignment operators be used with strings in PHP? Give an example.
Yes. For example,
$str = 'Hello'; $str .= ' World'; appends ' World' to $str, so $str becomes 'Hello World'.Click to reveal answer
What does
$a += 5; do in PHP?✗ Incorrect
The operator
+= adds the right value to the left variable and assigns the result back.Which operator assigns a value to a variable?
✗ Incorrect
The single equals sign
= is the assignment operator.What will be the value of
$x after $x = 10; $x -= 3;?✗ Incorrect
The
-= operator subtracts 3 from 10 and assigns 7 to $x.Which compound assignment operator appends a string in PHP?
✗ Incorrect
The
.= operator appends the right string to the left string variable.What does
$a *= 4; do if $a is 2?✗ Incorrect
It multiplies 2 by 4 and assigns 8 to
$a.Explain how the compound assignment operator
+= works in PHP with an example.Think about adding a number to a variable and saving it.
You got /3 concepts.
Describe the difference between the assignment operator
= and the compound assignment operator *=.One just sets a value, the other does math then sets.
You got /3 concepts.