Syntax
if (condition) {
code to be executed if condition is true;
}
PHP Code Sample
<?php
$t = date(
“H”
);
if
($t <
“20”
) {
echo
“Have a good day!”;
}
?>
![IF Statement Diagram-IF](https://uptodream.com/wp-content/uploads/2022/11/IF-Statement-Diagram-IF.png)
Syntax
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
PHP Code Sample
<?php
$t = date(
“H”
);
if
($t <
“20”
) {
echo
“Have a good day!”;
}
else
{
echo
“Have a good night!”;
}
?>
![IF Statement Diagram-IF - ELSE](https://uptodream.com/wp-content/uploads/2022/11/IF-Statement-Diagram-IF-ELSE.png)
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;
}
PHP Code Sample
<?php
$t = date(
“H”
);
if
($t <
“10”
) {
echo
“Have a good morning!”;
}
elseif
($t <
“20”
) {
echo
“Have a good day!”;
}
else
{
echo
“Have a good night!”;
}
?>
![IF Statement Diagram-IF - ELSE IF - ELSE](https://uptodream.com/wp-content/uploads/2022/11/IF-Statement-Diagram-IF-ELSE-IF-ELSE-1.png)