Bird
0
0

Which of the following is the correct syntax to assign $result to $a if set, otherwise to 10, using null coalescing?

easy📝 Syntax Q3 of 15
PHP - Conditional Statements
Which of the following is the correct syntax to assign $result to $a if set, otherwise to 10, using null coalescing?
A$result = $a ?: 10;
B$result = $a ?? 10;
C$result = $a ? 10;
D$result = ?? $a 10;
Step-by-Step Solution
Solution:
  1. Step 1: Recall null coalescing syntax

    The correct syntax is $variable = $value ?? default; to assign default if value is null or not set.
  2. Step 2: Check each option

    $result = $a ?? 10; correctly uses ?? operator. Others are invalid syntax or different operators.
  3. Final Answer:

    $result = $a ?? 10; -> Option B
  4. Quick Check:

    Correct null coalescing syntax is variable = value ?? default [OK]
Quick Trick: Use variable = value ?? default for null coalescing [OK]
Common Mistakes:
  • Using ?: instead of ??
  • Wrong operator placement
  • Syntax errors with ??

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes