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?
✗ Incorrect
Only option C is valid. It starts with $ followed by a letter or underscore, and uses only allowed characters (letters, numbers, and underscore). A starts with a number after $, B lacks $, and D contains a hyphen.
Are PHP variable names case-sensitive?
✗ Incorrect
PHP variable names are case-sensitive, so $Var and $var refer to different variables.
What is the first character of every PHP variable name?
✗ Incorrect
Every PHP variable name must start with a dollar sign ($).
Which character is NOT allowed in PHP variable names after the $?
✗ Incorrect
Hyphens (-) are not allowed in PHP variable names.
Is this variable name valid in PHP?
$_myVar123✗ Incorrect
Variable names can start with an underscore and contain numbers and uppercase letters.
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.