Challenge - 5 Problems
Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of compound assignment with strings
What is the output of this PHP code?
PHP
<?php $a = "Hello"; $a .= " World"; echo $a; ?>
Attempts:
2 left
💡 Hint
The .= operator adds the right string to the left string.
✗ Incorrect
The .= operator appends the right string to the left string variable. So $a becomes "Hello World".
❓ Predict Output
intermediate2:00remaining
Result of compound assignment with numbers
What is the value of $x after running this PHP code?
PHP
<?php $x = 10; $x *= 3 + 2; echo $x; ?>
Attempts:
2 left
💡 Hint
Remember operator precedence: multiplication and addition.
✗ Incorrect
The expression $x *= 3 + 2 is evaluated as $x *= (3 + 2) = $x *= 5, so $x becomes 10 * 5 = 50.
❓ Predict Output
advanced2:00remaining
Output of chained compound assignments
What is the output of this PHP code?
PHP
<?php $a = 5; $b = 10; $c = 15; $a += $b -= $c; echo "$a $b $c"; ?>
Attempts:
2 left
💡 Hint
Evaluate inner assignment first, then outer.
✗ Incorrect
First $b -= $c means $b = 10 - 15 = -5. Then $a += $b means $a = 5 + (-5) = 0. $c stays 15.
❓ Predict Output
advanced2:00remaining
Effect of compound assignment with arrays
What error or output does this PHP code produce?
PHP
<?php $arr = [1, 2, 3]; $arr += [4, 5]; print_r($arr); ?>
Attempts:
2 left
💡 Hint
The += operator for arrays adds elements with keys that do not exist in the left array.
✗ Incorrect
The += operator adds elements from the right array only if the key does not exist in the left array. The right array [4, 5] has keys 0=>4 and 1=>5, both exist in the left array, so nothing is added.
❓ Predict Output
expert2:00remaining
Final value after mixed compound assignments
What is the final value of $result after running this PHP code?
PHP
<?php $result = 2; $result *= 3; $result += 4; $result /= 2; $result -= 1; echo $result; ?>
Attempts:
2 left
💡 Hint
Calculate step by step following the order of operations.
✗ Incorrect
Step 1: $result = 2
Step 2: $result *= 3 → 6
Step 3: $result += 4 → 10
Step 4: $result /= 2 → 5
Step 5: $result -= 1 → 4
Output is 4.