Bird
0
0

You want to check if a variable $num is between 10 and 20 inclusive using logical operators. Which condition is correct?

hard📝 Application Q8 of 15
PHP - Operators
You want to check if a variable $num is between 10 and 20 inclusive using logical operators. Which condition is correct?
A$num >= 10 && $num <= 20
B$num > 10 || $num < 20
C$num >= 10 || $num <= 20
D$num > 10 && $num < 20
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range condition

    To check if $num is between 10 and 20 inclusive, it must be >= 10 and <= 20.
  2. Step 2: Analyze each option

    $num >= 10 && $num <= 20 correctly uses AND with inclusive bounds; others use OR or exclusive bounds.
  3. Final Answer:

    $num >= 10 && $num <= 20 -> Option A
  4. Quick Check:

    Range check uses AND with inclusive limits [OK]
Quick Trick: Use AND to combine range conditions [OK]
Common Mistakes:
  • Using OR instead of AND
  • Using exclusive > or < instead of >= or <=
  • Mixing conditions incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes