Complete the code to assign a null value to the variable.
<?php
$var = [1];
?>In PHP, null is the special value used to represent a variable with no value.
Complete the code to check if a variable is null.
<?php if ([1]($var)) { echo "Variable is null."; } ?>
isset() which returns false if variable is null but also false if variable is not set.empty() which returns true for many values, not just null.The function is_null() returns true if the variable is null.
Fix the error in the code to correctly assign null to the variable.
<?php
$var = [1];
?>NULL, which is accepted but lowercase is preferred.In PHP, the null value is null (case-insensitive, but lowercase is standard and preferred). Using quotes makes it a string, not null.
Fill both blanks to create an array with keys and values where some values are null.
<?php
$data = [
'name' => 'Alice',
'age' => [1],
'email' => [2]
];
?>The 'age' key has a null value, meaning no age is set. The 'email' key has a string value.
Fill all three blanks to create a function that returns null if input is empty, else returns input.
<?php
function checkInput($input) {
if (empty($input)) {
return [1];
} else {
return [2];
}
}
$result = checkInput([3]);
?>The function returns null if the input is empty (like an empty string), otherwise it returns the input itself. The function is called with an empty string.