0
0
PHPprogramming~5 mins

Variable naming rules in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What character must a PHP variable name start with?
A PHP variable name must start with a dollar sign ($). For example, $variable is valid.
Click to reveal answer
beginner
Can PHP variable names contain spaces or special characters like @ or #?
No, PHP variable names cannot contain spaces or special characters like @ or #. They can only contain letters, numbers, and underscores after the initial $.
Click to reveal answer
beginner
Are PHP variable names case-sensitive?
Yes, PHP variable names are case-sensitive. For example, $Name and $name are two different variables.
Click to reveal answer
beginner
Is $2ndValue a valid PHP variable name? Why or why not?
No, $2ndValue is not valid because variable names cannot start with a number after the dollar sign. The first character after $ must be a letter or underscore.
Click to reveal answer
beginner
What characters are allowed in PHP variable names after the initial $?
After the initial $, PHP variable names can contain letters (a-z, A-Z), numbers (0-9), and underscores (_). They cannot start with a number.
Click to reveal answer
Which of the following is a valid PHP variable name?
A$user_name
BuserName
C$9lives
D$user-name
Are PHP variable names case-sensitive?
AOnly in some PHP versions
BNo, $Var and $var are the same variable
CYes, $Var and $var are different variables
DOnly for variables starting with underscore
What is the first character of every PHP variable name?
A$
B_
Ca letter
Da number
Which character is NOT allowed in PHP variable names after the $?
Aa
B9
C_
D-
Is this variable name valid in PHP? $_myVar123
ANo, because it contains uppercase letters
BYes
CNo, because it contains numbers
DNo, because it starts with underscore
Explain the rules for naming variables in PHP.
Think about what characters are allowed and the importance of the $ sign.
You got /5 concepts.
    Why is $2ndValue not a valid variable name in PHP? What would be a valid alternative?
    Focus on the first character after the dollar sign.
    You got /2 concepts.