PHP Tutorial
Home
PHP Install Xampp
PHP Syntax & Comments
PHP Variables
PHP Constants
PHP Data Types
PHP Echo & Print
PHP Strings
PHP If...Else...Elseif
PHP Ternary Operator
PHP Loops
PHP Functions
PHP Arrays
PHP GET & POST
PHP Advanced
PHP Date and Time
PHP Include and Require
PHP File Upload
PHP Sessions
PHP Cookies
PHP Send Email
PHP JSON Parsing
PHP MySQL Database
PHP MySQL Introduction
PHP Connect to MySQL
PHP MySQL Create DB
PHP MySQL Create Table
PHP MySQL Insert Data
PHP MySQL Select Data
PHP MySQL Delete Data
PHP MySQL Update Data
PHP MySQL Where
PHP Conditional Statements
There are many statements available in PHP that you can use to make decisions :
The if Statement
The if statement is used to execute a block of code if condition is true then evaluates if block.
Syntax :
if (condition) { code to be executed if condition is true; }
Example :
<?php $t = date("H"); if ($t < "15") { echo "Have a good day!"; } ?>
The if else Statement
The if else statement first executes some code if a condition is true and another code if that condition is false.
Syntax :
if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
Example :
<?php $a = 20; $b = 10; if ($a >= $b) { echo "A is big!"; } else { echo "B is big!"; } ?>
The if elseif else Statement
The if elseif else statement is used to combine multiple if else statements.
Syntax :
if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if first condition is false and this condition is true; } else { code to be executed if all conditions are false; }
Example :
<?php $a = 20; $b = 10; if ($a > $b) { echo "A is big!"; } else if($b > $a){ echo "B is big!"; }else{ echo "A and B equals!"; } ?>