<!DOCTYPE html>
<html>
<head>
<title>PHP if statement</title>
</head>
<body>
<?php
$time = date("H");
if ($time < "18") {
echo "Have a good day!";
}
?>
</body>
</html>
PHP if-else statement is executed whether condition is true or false.
<!DOCTYPE html>
<html>
<head>
<title>PHP if...else statement</title>
</head>
<body>
<?php
$time = date("H");
if ($time < "18") {
echo "Hi, have a good day!";
} else {
echo "Hi, have a good night!";
}
?>
</body>
</html>
The if-else-if-else statement lets you chain together multiple if-else statements, thus allowing the programmer to define actions for more than just two possible outcomes.
<!DOCTYPE html>
<html>
<head>
<title>PHP if...elseif....else statement</title>
</head>
<body>
<?php
$time = date("H");
if ($time < "11") {
echo "Have a good morning!";
} elseif ($time < "18") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
</body>
</html>