Very often when you write code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this.
In PHP we have the following conditional statements:
1.if statement - executes some code if one condition is true
2.if...else statement - executes some code if a condition is true and another code if that condition is false
3.if...elseif...else statement - executes different codes for more than two conditions
4.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
<?php
if (5 > 3) {
// code to be executed if condition is true;
}
? >
<!DOCTYPE html> <html> <body> <?php # if statement in php $x =5; if(x>3){ echo $x." is greater than 3"; }else{ echo $x." is less than 3";} ?> </body> </html>