Bird
0
0

Which of the following correctly declares a variable called $city in PHP?

easy📝 Syntax Q3 of 15
PHP - Variables and Data Types
Which of the following correctly declares a variable called $city in PHP?
Acity = 'New York';
B$city = 'New York';
C$city := 'New York';
Dvar city = 'New York';
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP variable syntax

    Variables in PHP start with a $ sign followed by the variable name.
  2. Step 2: Check each option

    $city = 'New York'; uses correct syntax with $ and assignment operator =. Options B, C, and D use invalid syntax for PHP.
  3. Final Answer:

    $city = 'New York'; -> Option B
  4. Quick Check:

    PHP variables start with $ [OK]
Quick Trick: PHP variables always start with $ [OK]
Common Mistakes:
  • Omitting the $ sign before variable name
  • Using := instead of = for assignment
  • Using JavaScript syntax like var

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes