0
0
PHPprogramming~5 mins

Variable declaration with dollar sign in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIt marks the start of a variable name
BIt is used for comments
CIt declares a function
DIt ends a statement
Which of these is a valid PHP variable name?
A$2ndPlace
B$_score
C$-value
D$ name
How do you assign the number 10 to a variable named count in PHP?
A$count = 10;
B#count = 10;
Cvar count = 10;
Dcount = 10;
What will this PHP code output? <br>$name = "Bob"; echo $name;
Aname
B$name
CBob
DError
Can you declare two variables like this in PHP? <br>$a = 5, $b = 10;
AOnly if inside a function
BNo, variables must be declared on separate lines
CNo, commas are not allowed in variable declarations
DYes, this is valid syntax
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.