PHP - Variables and Data TypesYou want to store a user's age and then increase it by 1 in PHP. Which code correctly does this?AAll of the aboveB$age = 30; $age++; echo $age;C$age = 30; $age += 1; echo $age;D$age = 30; $age = $age + 1; echo $age;Check Answer
Step-by-Step SolutionSolution: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;Step 2: Confirm all increase age by 1All three methods correctly increase $age by 1 and then print it.Final Answer:All of the above -> Option AQuick Check:Multiple ways to increment variable [OK]Quick Trick: Increment variables using +, +=, or ++ [OK]Common Mistakes:Using wrong operatorsForgetting to assign backExpecting only one correct method
Master "Variables and Data Types" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Arrays - Array search functions - Quiz 7medium Arrays - Array access and modification - Quiz 9hard Conditional Statements - Switch statement execution - Quiz 12easy Conditional Statements - Match expression (PHP 8) - Quiz 8hard Conditional Statements - If statement execution flow - Quiz 12easy Functions - Function declaration and calling - Quiz 6medium Loops - Foreach loop for arrays - Quiz 15hard Operators - String concatenation operator - Quiz 9hard PHP Basics and Execution Model - PHP tags and embedding in HTML - Quiz 12easy Type Handling - Type casting syntax - Quiz 8hard