Usage of PHPelseif

藏色散人
Release: 2023-02-27 14:32:01
Original
3141 people have browsed it

Usage of PHPelseif

PHP - if...elseif....else statement

Please use if.... elseif...else statement to execute different code based on two or more conditions.

Syntax

if (条件) {
  条件为 true 时执行的代码;
} elseif (condition) {
  条件为 true 时执行的代码;
} else {
  条件为 false 时执行的代码;
}
Copy after login

If the current time (HOUR) is less than 10, the following example will output "Have a good morning!", if the current time is less than 20, then output "Have a good day!" . Otherwise, "Have a good night!" will be output:

Example

<?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!";
}
?>
Copy after login

Output:

Have a good morning!
Copy after login

For more PHP related knowledge, please visit PHP Chinese net!

The above is the detailed content of Usage of PHPelseif. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template