Home > Backend Development > PHP Problem > Usage of php conditional statement if..else

Usage of php conditional statement if..else

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

Usage of php conditional statement if..else

Usage of php conditional statement if..else

PHP - if...else statement

To execute a block of code when the condition is true, and to execute another block of code when the condition is not true, please use the if....else statement.

Syntax

if (条件)
{
条件成立时执行的代码;
}
else
{
条件不成立时执行的代码;
}
Copy after login

If the current time is less than 20, the following example will output "Have a good day!", otherwise it will output "Have a good night!":

Example

<?php
$t=date("H");
if ($t<"20")
{
    echo "Have a good day!";
}
else
{
    echo "Have a good night!";
}
?>
Copy after login

Output:

Have a good day!
Copy after login

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

The above is the detailed content of Usage of php conditional statement if..else. 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