Bird
0
0

You want to store a user's age in a variable and then increase it by 1. Which PHP code correctly does this?

hard📝 Application Q8 of 15
PHP - Variables and Data Types
You want to store a user's age in a variable and then increase it by 1. Which PHP code correctly does this?
Aage = 20; age++; echo age;
B$age = 20; $age += 1; echo age;
C$age := 20; $age++; echo $age;
D$age = 20; $age = $age + 1; echo $age;
Step-by-Step Solution
Solution:
  1. Step 1: Check variable declaration and increment

    Variable must start with $, assignment uses =, increment can be done by adding 1.
  2. Step 2: Verify each option

    $age = 20; $age = $age + 1; echo $age; correctly declares $age, adds 1, and echoes $age. Others miss $ or use invalid syntax.
  3. Final Answer:

    $age = 20; $age = $age + 1; echo $age; -> Option D
  4. Quick Check:

    Correct variable use and increment = $age = 20; $age = $age + 1; echo $age; [OK]
Quick Trick: Use $ for variables and += or + for increment [OK]
Common Mistakes:
  • Missing $ before variable
  • Using := instead of =
  • Echoing variable without $

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes