PHP - Variables and Data TypesYou 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;Check Answer
Step-by-Step SolutionSolution:Step 1: Check variable declaration and incrementVariable must start with $, assignment uses =, increment can be done by adding 1.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.Final Answer:$age = 20; $age = $age + 1; echo $age; -> Option DQuick 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 variableUsing := instead of =Echoing variable without $
Master "Variables and Data Types" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Arrays - Array sort functions - Quiz 15hard Conditional Statements - Elseif ladder execution - Quiz 15hard Functions - Why functions are needed - Quiz 1easy Operators - Comparison operators (loose and strict) - Quiz 7medium Output and String Handling - Printf and sprintf formatting - Quiz 15hard Output and String Handling - Why output functions matter - Quiz 13medium PHP Basics and Execution Model - What is PHP - Quiz 4medium PHP Request Lifecycle - Script execution and memory reset - Quiz 7medium Type Handling - Type casting syntax - Quiz 8hard Variables and Data Types - String type (single vs double quotes) - Quiz 15hard