Php if else
frequently when you write code, you need to perform various activities for various choices. you can utilize conditional statements(If...Else Statement) in your code to do this.
The If...Else Statement
In the event that you need to execute some code if a condition is valid and another code if a condition is false, utilize the if...else statement.
Syntax
if (condition) { code to be executed if condition is true } else { code to be executed if condition is false }
Example
<html> <body> <?php $d = date('D'); if($d=='Fri'){ echo "Have a nice weekend"; }else{ echo "Have a nice day"; } ?> </body> </html>
The following example will output "Have a nice weekend" if the current day is Friday, otherwise, it will output "Have a nice day".
The Else If Statement
On the off chance that you need to execute some code and on the off chance that one of a few conditions are true to use the else if statement.
Syntax
if (condition){ code to be executed if condition is true } elseif(condition){ code to be executed if condition is true } else{ code to be executed if condition is false }
Example
<html> <body> <?php $d = date('D'); if($d=='Fri'){ echo "Have a nice weekend"; }elseif($d=='Sun'){ echo "Have a nice Sunday"; } else{ echo "Have a nice day"; } ?> </body> </html>
The following example will output "Have a nice weekend" if the current day is Friday. and "Have a nice Sunday"; if the current day is Sunday. otherwise, it will output "Have a nice day".