Recall & Review
beginner
What symbol is used to declare a variable in PHP?
In PHP, variables are declared using the dollar sign
$ before the variable name, like $variableName.Click to reveal answer
beginner
Why does PHP use a dollar sign
$ before variable names?The dollar sign
$ tells PHP that what follows is a variable. It helps PHP recognize variables easily in the code.Click to reveal answer
beginner
Is this a valid PHP variable declaration? <br>
$name = "Alice";Yes, this is valid. The variable
$name is declared and assigned the string value "Alice".Click to reveal answer
beginner
Can variable names in PHP start with a number? For example, is
$1name valid?No, variable names cannot start with a number. They must start with a letter or underscore after the dollar sign.
Click to reveal answer
beginner
How do you declare multiple variables in PHP using the dollar sign?
You declare each variable with its own dollar sign, for example:
$a = 1; $b = 2;. Each variable needs its own $.Click to reveal answer
What does the dollar sign
$ mean in PHP variable declaration?✗ Incorrect
The dollar sign
$ tells PHP that the following word is a variable name.Which of these is a valid PHP variable name?
✗ Incorrect
Variable names must start with a letter or underscore after the dollar sign.
$_score is valid.How do you assign the number 10 to a variable named
count in PHP?✗ Incorrect
In PHP, variables start with
$, so $count = 10; is correct.What will this PHP code output? <br>
$name = "Bob"; echo $name;✗ Incorrect
The variable
$name holds "Bob", so echo prints "Bob".Can you declare two variables like this in PHP? <br>
$a = 5, $b = 10;✗ Incorrect
Yes, this is valid syntax. You can declare multiple variables separated by commas like
$a = 5, $b = 10;.Explain how to declare a variable in PHP and why the dollar sign is necessary.
Think about how PHP knows something is a variable.
You got /3 concepts.
Describe the rules for naming variables in PHP after the dollar sign.
Consider what characters are allowed at the start and inside variable names.
You got /4 concepts.