0
0
PHPprogramming~20 mins

Why operators matter in PHP - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
?>
A15
B14
C13
D12
Attempts:
2 left
💡 Hint
Remember multiplication and division happen before addition and subtraction.
Predict Output
intermediate
2: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";
?>
A8,8
B53,8
C53,53
D8,53
Attempts:
2 left
💡 Hint
The plus operator converts strings to numbers, dot operator concatenates strings.
Predict Output
advanced
2: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';
}
?>
AYes
BNo
CSyntax Error
D0
Attempts:
2 left
💡 Hint
Bitwise AND and OR produce non-zero values, which are true in logical context.
Predict Output
advanced
2:00remaining
Output of increment operators in expressions
What does this PHP code output?
PHP
<?php
$a = 5;
$b = $a++ + ++$a;
echo $b;
?>
A12
B13
C10
D11
Attempts:
2 left
💡 Hint
Post-increment returns the value before increment, pre-increment increments first.
Predict Output
expert
2: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";
?>
A8,14
B14,10
C14,8
D10,14
Attempts:
2 left
💡 Hint
Assignment operators evaluate right to left, watch the order carefully.