Challenge - 5 Problems
PHP Variable Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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; ?>
Attempts:
2 left
💡 Hint
Remember PHP variable names cannot start with a number.
✗ Incorrect
In PHP, variable names must start with a letter or underscore. $3var starts with a digit, causing a syntax error.
❓ Predict Output
intermediate2:00remaining
PHP Variable Naming: Case Sensitivity
What will be the output of this PHP code?
PHP
<?php $Var = 5; $var = 10; echo $Var + $var; ?>
Attempts:
2 left
💡 Hint
PHP variable names are case sensitive.
✗ Incorrect
PHP treats $Var and $var as two different variables. So 5 + 10 = 15.
❓ Predict Output
advanced2:00remaining
PHP Variable Naming: Valid or Invalid?
Which variable name is invalid in PHP?
Attempts:
2 left
💡 Hint
PHP variable names cannot contain hyphens.
✗ Incorrect
Hyphens are not allowed in PHP variable names because they are interpreted as minus operators.
❓ Predict Output
advanced2:00remaining
PHP Variable Naming: Output Prediction
What will this PHP code output?
PHP
<?php $var = 1; $Var = 2; $VAR = 3; echo $var + $Var + $VAR; ?>
Attempts:
2 left
💡 Hint
PHP variable names are case sensitive.
✗ Incorrect
Each variable is distinct: 1 + 2 + 3 = 6.
❓ Predict Output
expert2: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; ?>
Attempts:
2 left
💡 Hint
Underscores and numbers are allowed in variable names as long as they don't start with a number.
✗ Incorrect
All three variables are valid and distinct. Their sum is 5 + 10 + 15 = 30.