PHP - LoopsWhich of the following is the correct syntax for a nested for loop in PHP?Afor ($i = 0; $i < 2; $i++) { for $j = 0; $j < 3; $j++ { echo $i . $j; } }Bfor ($i = 0; $i < 2; $i++) { for ($j = 0; $j < 3; $j++) { echo $i . $j; } }Cfor ($i = 0; $i < 2; $i++) for ($j = 0; $j < 3; $j++) echo $i . $j;Dfor $i = 0; $i < 2; $i++ { for $j = 0; $j < 3; $j++ { echo $i . $j; } }Check Answer
Step-by-Step SolutionSolution:Step 1: Check PHP for loop syntaxPHP requires parentheses around loop conditions and braces for blocks.Step 2: Validate nested loop syntaxfor ($i = 0; $i < 2; $i++) { for ($j = 0; $j < 3; $j++) { echo $i . $j; } } uses correct parentheses and braces for both loops and echo statement inside.Final Answer:for ($i = 0; $i < 2; $i++) { for ($j = 0; $j < 3; $j++) { echo $i . $j; } } -> Option BQuick Check:Correct parentheses and braces in nested loops [OK]Quick Trick: Use parentheses and braces properly in PHP loops [OK]Common Mistakes:Omitting parentheses around loop conditionsMissing braces for loop blocksIncorrect for loop syntax without $ sign
Master "Loops" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Arrays - Array merge and combine - Quiz 2easy Arrays - Indexed array creation - Quiz 12easy Conditional Statements - Ternary operator - Quiz 6medium Functions - Return type declarations - Quiz 15hard Loops - Break statement with levels - Quiz 10hard Loops - While loop execution model - Quiz 1easy PHP Basics and Execution Model - PHP tags and embedding in HTML - Quiz 2easy Type Handling - Type coercion in operations - Quiz 1easy Type Handling - Why type awareness matters - Quiz 5medium Variables and Data Types - Why variables are needed in PHP - Quiz 8hard