Recall & Review
beginner
What is the purpose of an if-else statement in PHP?
An if-else statement lets the program choose between two paths based on a condition. If the condition is true, it runs one block of code; if false, it runs another.
Click to reveal answer
beginner
How do you write a simple if-else statement in PHP?
Use
if (condition) { ... } else { ... }. The code inside the if block runs if the condition is true; otherwise, the else block runs.Click to reveal answer
beginner
What happens if the if condition is false and there is no else block?
If the condition is false and no else block exists, PHP skips the if block and continues running the rest of the code.
Click to reveal answer
intermediate
Can you have multiple conditions checked in PHP using if-else?
Yes, you can use
elseif to check multiple conditions in order. PHP runs the block for the first true condition it finds.Click to reveal answer
beginner
Why is if-else important in programming?
If-else lets programs make decisions, like choosing what to do next based on data or user input. It makes programs flexible and interactive.
Click to reveal answer
What will this PHP code output?<br>
<?php
$age = 20;
if ($age >= 18) {
echo "Adult";
} else {
echo "Child";
}
?>✗ Incorrect
Since $age is 20, which is greater than or equal to 18, the if block runs and outputs 'Adult'.
What happens if the if condition is false and there is no else block?
✗ Incorrect
Without an else block, if the condition is false, PHP skips the if block and continues running the rest of the code.
Which keyword lets you check multiple conditions in PHP?
✗ Incorrect
The 'elseif' keyword lets you check multiple conditions in sequence inside if-else statements.
What is the correct syntax for an if-else statement in PHP?
✗ Incorrect
PHP requires parentheses around the condition and curly braces for code blocks: if (condition) { ... } else { ... }
Why do programmers use if-else statements?
✗ Incorrect
If-else statements let programs choose different actions depending on conditions, enabling decision-making.
Explain how an if-else statement controls the flow of a PHP program.
Think about how the program chooses which code to run.
You got /4 concepts.
Describe the difference between if, else if, and else in PHP.
Consider how multiple choices are handled.
You got /3 concepts.