0
0
PHPprogramming~10 mins

Null type and its meaning 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 assign a null value to the variable.

PHP
<?php
$var = [1];
?>
Drag options to blanks, or click blank then click option'
Afalse
B0
C"null"
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or false instead of null.
Using the string "null" instead of the null value.
2fill in blank
medium

Complete the code to check if a variable is null.

PHP
<?php
if ([1]($var)) {
    echo "Variable is null.";
}
?>
Drag options to blanks, or click blank then click option'
Ais_null
Bisset
Cempty
Dis_string
Attempts:
3 left
💡 Hint
Common Mistakes
Using isset() which returns false if variable is null but also false if variable is not set.
Using empty() which returns true for many values, not just null.
3fill in blank
hard

Fix the error in the code to correctly assign null to the variable.

PHP
<?php
$var = [1];
?>
Drag options to blanks, or click blank then click option'
ANULL
BNull
Cnull
D"null"
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase NULL, which is accepted but lowercase is preferred.
Using quotes which makes it a string, not null.
4fill in blank
hard

Fill both blanks to create an array with keys and values where some values are null.

PHP
<?php
$data = [
    'name' => 'Alice',
    'age' => [1],
    'email' => [2]
];
?>
Drag options to blanks, or click blank then click option'
Anull
B"alice@example.com"
C0
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or false instead of null for missing age.
Not using quotes around the email string.
5fill in blank
hard

Fill all three blanks to create a function that returns null if input is empty, else returns input.

PHP
<?php
function checkInput($input) {
    if (empty($input)) {
        return [1];
    } else {
        return [2];
    }
}

$result = checkInput([3]);
?>
Drag options to blanks, or click blank then click option'
Anull
B$input
C""
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 or false instead of null for empty input.
Not returning the input variable in the else branch.
Calling the function with a value other than an empty string.