Recall & Review
beginner
What does an
if statement do in PHP?An
if statement checks a condition. If the condition is true, it runs the code inside its block. If false, it skips that code.Click to reveal answer
beginner
What happens when the
if condition is false and there is no else block?The code inside the
if block is skipped, and the program continues with the next statement after the if block.Click to reveal answer
beginner
How does an
else block work with an if statement?The
else block runs only when the if condition is false. It provides an alternative set of instructions.Click to reveal answer
intermediate
What is the role of
elseif in PHP's if statement execution flow?elseif lets you check multiple conditions one after another. It runs the block for the first true condition it finds.Click to reveal answer
intermediate
Explain the execution flow of this PHP code:<br>
if ($a > 10) { echo 'Big'; } elseif ($a > 5) { echo 'Medium'; } else { echo 'Small'; }PHP checks if
$a is greater than 10. If yes, it prints 'Big'. If not, it checks if $a is greater than 5. If yes, it prints 'Medium'. Otherwise, it prints 'Small'. Only one block runs.Click to reveal answer
What happens if the
if condition is true?✗ Incorrect
When the
if condition is true, PHP runs the code inside the if block.Which block runs if the
if condition is false and there is an else block?✗ Incorrect
If the
if condition is false, the else block runs if it exists.What does
elseif allow you to do?✗ Incorrect
elseif lets you check more than one condition in order.In this code, what will print if
$a = 7?<br>if ($a > 10) { echo 'Big'; } elseif ($a > 5) { echo 'Medium'; } else { echo 'Small'; }✗ Incorrect
7 is not greater than 10, but it is greater than 5, so 'Medium' prints.
If none of the
if or elseif conditions are true, what happens?✗ Incorrect
The
else block runs when all previous conditions are false.Describe how PHP decides which block of code to run in an if-elseif-else statement.
Think about the order PHP checks conditions and what happens when one is true.
You got /5 concepts.
Explain what happens when an if statement has no else block and the condition is false.
Consider what PHP does when it finds no code to run inside the if.
You got /3 concepts.