Bird
0
0

Which of the following is the correct syntax to check if a variable $var is not null in PHP?

easy📝 Syntax Q3 of 15
PHP - Type Handling
Which of the following is the correct syntax to check if a variable $var is not null in PHP?
Aif ($var !== null)
Bif (is_null($var))
Cif (!isset($var))
Dif (empty($var))
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to check not null

    To check if variable is not null, compare it directly with null using !== operator.
  2. Step 2: Analyze options

    is_null($var) checks if null (not not null), !isset($var) checks if variable is not set or null, empty() checks for many falsy values.
  3. Final Answer:

    if ($var !== null) -> Option A
  4. Quick Check:

    Not null check = $var !== null [OK]
Quick Trick: Use !== null to check variable is not null [OK]
Common Mistakes:
  • Using is_null() instead of negation
  • Confusing isset() with null check
  • Using empty() for null check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes