PHP If ... Else Simple Tutorial
, if ElseIf's reports and other PHP are used to perform different actions, depending on the conditions.
-------------------------------------------------- ------------------------------
Conditional statement
Often when you write code, you want to perform different actions for different decisions.
You can do this by using the code in the conditional statement.
If ... else statement-Use this declaration if you want to execute the code set when one condition is true, the other case if it is not correct
ElseIf's statement-is used if. .. The e LSE statement executes a set of code if one of the conditions is true
-------------------------------------------------- ------------------------------
The If ... else statement
If you want to execute some code, if a condition is true, if the condition of another code is false, if you use .... else statement.
Grammar
if (condition)
code to was executed if condition is true;
Else
code to was executed if condition is false;
For example
The following example will output "wish you a happy weekend!" "If the current day is Friday, otherwise it will produce" Wish you a day! ” :
<?php
$d =date ("D");
if ($d = = "Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
? >
</body>
For example
The following example will output "wish you a happy weekend!" "If the current day is Friday, otherwise it will produce" Wish you a day! ” :
<?php
$d =date ("D");
if ($d = = "Fri")
{
echo "hello!<br/>";
echo "Have a nice weekend!";
echo "in monday!";
>
</body>
in ElseIf declaration
if you want to execute some code if one of the conditions is true using ElseIf's declaration
Syntax
if (
Condition) code to was executed if condition is true;
ElseIf (condition) code to was executed if condition is true;
Else code to was executed if condition is false;
For example
The following example will output "wish you a happy weekend!" "If the present day is Friday, and" Wish you Sunday! "If the present day is Sunday. Otherwise, the output "Wish you a day!" ":
<?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>