Bird
0
0

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

hard📝 Application Q8 of 15
PHP - Variables and Data Types
You want to store a user's age and then increase it by 1 in PHP. Which code correctly does this?
AAll of the above
B$age = 30; $age++; echo $age;
C$age = 30; $age += 1; echo $age;
D$age = 30; $age = $age + 1; echo $age;
Step-by-Step Solution
Solution:
  1. Step 1: Review each code snippet

    $age = 30; $age = $age + 1; echo $age; adds 1 using $age = $age + 1; $age = 30; $age++; echo $age; uses increment operator $age++; $age = 30; $age += 1; echo $age; uses shorthand $age += 1;
  2. Step 2: Confirm all increase age by 1

    All three methods correctly increase $age by 1 and then print it.
  3. Final Answer:

    All of the above -> Option A
  4. Quick Check:

    Multiple ways to increment variable [OK]
Quick Trick: Increment variables using +, +=, or ++ [OK]
Common Mistakes:
  • Using wrong operators
  • Forgetting to assign back
  • Expecting only one correct method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes