PHP if Statements
PHP if statements are conditional statements used to control the flow of your code based on whether a certain condition is true or false
PHP Conditional Statements
Conditional statements are fundamental building blocks in PHP programming. They allow you to control the flow of your code based on specific conditions, making your programs more dynamic and adaptable.
In PHP we have the following conditional statements:
• if statement - executes some code if one condition is true
• if...else statement - executes some code if a condition is true and another code if that condition is false
• if...elseif...else statement - executes different codes for more than two conditions
• switch statement - selects one of many blocks of code to be executed
PHP - The if Statement
The if statement executes some code if one condition is true.
Syntax
if (condition) {
// code to be executed if condition is true;
}
Example
<!DOCTYPE html> <html> <body> <?php if (5 > 3) { echo "Welcome to Codelines!"; } ?> </body> </html>
Output
Welcome to Codelines!