Home >Backend Development >PHP Tutorial >PHP process control, php process_PHP tutorial

PHP process control, php process_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:51:13863browse

PHP process control, php process

PHP - if statement

The

if statement is used to execute code only when the specified condition is true.

Grammar

if (条件)
{
条件成立时要执行的代码;
}

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

Example

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

Run

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.

Grammar

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

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!":

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

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

To execute a block of code when one of several conditions is true, use the if....else if...else statement. .

Grammar

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

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

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

 

Original address: http://www.manongjc.com/php/php_if_switch.html

Related reading:

php date_sunrise() gets the sunrise time based on the location (latitude and longitude)

php global legal time zone list

php date_default_timezone_set() sets the default time zone for date/time functions

php date_default_timezone_get() gets the default time zone used by date and time functions

php checkdate() function verifies whether the date is legal (correct)

A must-have for climbing Mount Tai to watch the sunrise - Mount Tai’s sunrise time list

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1131138.htmlTechArticlePHP process control, php process PHP - if statement The if statement is used to execute code only when the specified condition is true. Syntax if (condition){code to be executed when the condition is true;} If the current time is less than...
Statement:
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