Bird
0
0

Which of the following is a valid variable name in PHP?

easy📝 Conceptual Q11 of 15
PHP - Variables and Data Types
Which of the following is a valid variable name in PHP?
A$user_name
B2ndUser
Cuser-name
Duser name
Step-by-Step Solution
Solution:
  1. Step 1: Check the first character of each variable

    PHP variables must start with a $ followed by a letter or underscore, not a number or space.
  2. Step 2: Validate allowed characters

    Variable names can only contain letters, numbers, and underscores after the $. Spaces and hyphens are not allowed.
  3. Final Answer:

    $user_name -> Option A
  4. Quick Check:

    Starts with $ and uses letters/underscore [OK]
Quick Trick: Variable names start with $ and no spaces or hyphens [OK]
Common Mistakes:
  • Starting variable with a number
  • Using spaces or hyphens in variable names
  • Omitting the $ sign at the start

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes