0
0
PHPprogramming~20 mins

Variable naming rules in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Variable Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
PHP Variable Naming: Output Check
What is the output of this PHP code snippet?
PHP
<?php
$var1 = 10;
$_var2 = 20;
$3var = 30;
echo $var1 + $_var2;
?>
ASyntax error
B30
C50
DNotice: Undefined variable
Attempts:
2 left
💡 Hint
Remember PHP variable names cannot start with a number.
Predict Output
intermediate
2:00remaining
PHP Variable Naming: Case Sensitivity
What will be the output of this PHP code?
PHP
<?php
$Var = 5;
$var = 10;
echo $Var + $var;
?>
A15
B10
C5
DUndefined variable error
Attempts:
2 left
💡 Hint
PHP variable names are case sensitive.
Predict Output
advanced
2:00remaining
PHP Variable Naming: Valid or Invalid?
Which variable name is invalid in PHP?
A$_userName
B$user_name
C$user-name
D$UserName123
Attempts:
2 left
💡 Hint
PHP variable names cannot contain hyphens.
Predict Output
advanced
2:00remaining
PHP Variable Naming: Output Prediction
What will this PHP code output?
PHP
<?php
$var = 1;
$Var = 2;
$VAR = 3;
echo $var + $Var + $VAR;
?>
A1
B3
CUndefined variable error
D6
Attempts:
2 left
💡 Hint
PHP variable names are case sensitive.
Predict Output
expert
2:00remaining
PHP Variable Naming: Complex Output
What is the output of this PHP code?
PHP
<?php
$var = 5;
$var_2 = 10;
$var2 = 15;
echo $var + $var_2 + $var2;
?>
ASyntax error
B30
C25
DUndefined variable error
Attempts:
2 left
💡 Hint
Underscores and numbers are allowed in variable names as long as they don't start with a number.