search
Homephp教程php手册PHP流程控制,php流程

PHP流程控制,php流程

PHP - if 语句

if 语句用于仅当指定条件成立时执行代码

语法

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

如果当前时间小于 20,下面的实例将输出 "Have a good day!":

实例

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

运行

 

PHP - if...else 语句

在条件成立时执行一块代码,条件不成立时执行另一块代码,请使用 if....else 语句。

语法

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

如果当前时间小于 20,下面的实例将输出 "Have a good day!",否则输出 "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 语句

在若干条件之一成立时执行一个代码块,请使用 if....else if...else 语句。.

语法

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

如果当前时间小于 10,下面的实例将输出 "Have a good morning!",如果当前时间不小于 10 且小于 20,则输出 "Have a good day!",否则输出 "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!";
}
?>

  

原文地址:http://www.manongjc.com/php/php_if_switch.html

相关阅读:

php date_sunrise()根据地点(经度纬度)获取日出时间

php 全球合法时区列表大全

php date_default_timezone_set() 设置日期/时间函数的默认时区

php date_default_timezone_get()获取日期时间函数所使用的默认时区

php checkdate()函数验证日期是否合法(正确)

爬泰山看日出必备 - 泰山日出时间一览表

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools