0
0
PHPprogramming~10 mins

Why operators matter in PHP - Test Your Understanding

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

Complete 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'
A-
B*
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
2fill in blank
medium

Complete 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'
A==
B!=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment = instead of comparison ==.
3fill in blank
hard

Fix 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'
A-
B*
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or division instead of multiplication.
4fill in blank
hard

Fill 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'
A**
B>
C<
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of power, or wrong comparison operator.
5fill in blank
hard

Fill 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'
Astrtoupper
B>
C<
Dstrtolower
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase function or wrong comparison operators.