Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add two numbers and print the result.
PHP
<?php $a = 5; $b = 3; $result = $a [1] $b; echo $result; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
✗ Incorrect
The plus operator + adds two numbers together.
2fill in blank
mediumComplete the code to check if two values are equal.
PHP
<?php $x = 10; $y = 10; if ($x [1] $y) { echo 'Equal'; } else { echo 'Not equal'; } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment
= instead of comparison ==.✗ Incorrect
The double equals == operator checks if two values are equal.
3fill in blank
hardFix the error in the code to multiply two numbers correctly.
PHP
<?php $num1 = 4; $num2 = 7; $product = $num1 [1] $num2; echo $product; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or division instead of multiplication.
✗ Incorrect
The asterisk * operator multiplies two numbers.
4fill in blank
hardFill both blanks to create an array of squares for numbers greater than 3.
PHP
<?php $numbers = [1, 2, 3, 4, 5]; $squares = array_filter(array_map(fn($n) => $n[1]2, $numbers), fn($n) => $n [2] 9); print_r($squares); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of power, or wrong comparison operator.
✗ Incorrect
The ** operator raises to a power. The filter keeps squares greater than 9.
5fill in blank
hardFill all three blanks to create an associative array with keys as uppercase letters and values greater than 2.
PHP
<?php $items = ['a' => 1, 'b' => 3, 'c' => 5]; $result = array_filter(array_combine(array_map(fn($k) => [1]($k), array_keys($items)), $items), fn($v) => $v [2] 2 && $v [3] 6); print_r($result); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase function or wrong comparison operators.
✗ Incorrect
strtoupper converts keys to uppercase. Values are filtered to be greater than 2 and less than 6.