0
0
PHPprogramming~10 mins

Operator precedence and evaluation in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add 2 and 3, then multiply the result by 4.

PHP
<?php
$result = (2 + 3) [1] 4;
echo $result;
?>
Drag options to blanks, or click blank then click option'
A*
B/
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * causes the result to be 5 + 4 = 9, which is incorrect.
Forgetting parentheses changes the order of operations.
2fill in blank
medium

Complete the code to check if 5 is greater than 3 and less than 10.

PHP
<?php
if (5 [1] 3 && 5 < 10) {
    echo 'True';
} else {
    echo 'False';
}
?>
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' reverses the comparison and gives false.
Using '==' checks equality, not greater than.
3fill in blank
hard

Fix the error in the expression to correctly calculate 10 minus 3 times 2.

PHP
<?php
$result = 10 - 3 [1] 2;
echo $result;
?>
Drag options to blanks, or click blank then click option'
A+
B/
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' changes the result incorrectly.
Using '-' again causes wrong calculation.
4fill in blank
hard

Fill both blanks to create an array with keys as numbers and values as their squares, but only for numbers less than 5.

PHP
<?php
$squares = [];
for ($i = 1; $i <= 6; $i++) if ($i < 5) $squares[[1]] = [2];
print_r($squares);
?>
Drag options to blanks, or click blank then click option'
A$i
B$i * $i
C$i + $i
D$i - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication for squares.
Using wrong keys that don't match the numbers.
5fill in blank
hard

Fill all three blanks to create an associative array with uppercase keys, values as numbers, and only include values greater than 2.

PHP
<?php
$numbers = [1, 2, 3, 4];
$result = [];
foreach ($numbers as [3]) if ([2] > 2) $result[[1]] = [2];
print_r($result);
?>
Drag options to blanks, or click blank then click option'
Astrtoupper($num)
B$num
D$number
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not converting keys to uppercase.