Challenge - 5 Problems
Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed operator precedence
What is the output of this PHP code snippet?
PHP
<?php $result = 2 + 3 * 4 - 5 / 5; echo $result; ?>
Attempts:
2 left
💡 Hint
Remember multiplication and division happen before addition and subtraction.
✗ Incorrect
Multiplication and division are done first: 3*4=12 and 5/5=1. Then addition and subtraction: 2+12=14, 14-1=13.
❓ Predict Output
intermediate2:00remaining
Output of string concatenation and addition
What will this PHP code output?
PHP
<?php $a = '5'; $b = 3; $c = $a + $b; $d = $a . $b; echo "$c,$d"; ?>
Attempts:
2 left
💡 Hint
The plus operator converts strings to numbers, dot operator concatenates strings.
✗ Incorrect
Adding '5' + 3 converts '5' to 5, so 5+3=8. Concatenating '5' . 3 results in '53'.
❓ Predict Output
advanced2:00remaining
Output of combined logical and bitwise operators
What is the output of this PHP code?
PHP
<?php $x = 6; // binary 110 $y = 3; // binary 011 if (($x & $y) && ($x | $y)) { echo 'Yes'; } else { echo 'No'; } ?>
Attempts:
2 left
💡 Hint
Bitwise AND and OR produce non-zero values, which are true in logical context.
✗ Incorrect
($x & $y) = 2 (true), ($x | $y) = 7 (true), so condition is true and 'Yes' is printed.
❓ Predict Output
advanced2:00remaining
Output of increment operators in expressions
What does this PHP code output?
PHP
<?php $a = 5; $b = $a++ + ++$a; echo $b; ?>
Attempts:
2 left
💡 Hint
Post-increment returns the value before increment, pre-increment increments first.
✗ Incorrect
Initially $a=5. $a++ returns 5 then $a=6. ++$a increments $a to 7 then returns 7. So 5+7=12.
❓ Predict Output
expert2:00remaining
Output of complex operator chaining with assignment
What is the output of this PHP code?
PHP
<?php $x = 4; $y = 2; $x += $y *= $x + 1; echo "$x,$y"; ?>
Attempts:
2 left
💡 Hint
Assignment operators evaluate right to left, watch the order carefully.
✗ Incorrect
First $x + 1 = 5. Then $y *= 5 → $y = 2*5 = 10. Then $x += $y → $x = 4 + 10 = 14. Output: 14,10