作者:孙运动
在PHP中,最简单的条件语句的形式是 "if" 语句,一般如下所示:
--------------------------------------------------------------------------------
if (条件)
{
do this!
}
--------------------------------------------------------------------------------
这里的 "条件" 是一个条件的描述, PHP经过判断将得出"true"或"false"的任意之一值。如果是真值,所有大括弧里的PHP代码将被执行,相反,如果是假值大括弧里的代码将被忽略,继续执行"if"语句结构块以后的行。
我们通过给上面的 "login.php"脚本添加一个身份认证的例子来给你演示 "if" 语句是如何工作的。只有当用户输入的用户名是"neo"时才允许接入。
--------------------------------------------------------------------------------
// 检查名字并反馈相应的信息
if ($name == "neo")
{
?>
欢迎进入母体,Neo。
也许是武力强迫你才这样做的,,,哦,不正当的影片!
}
?>
//如果密码错了的话
if ($name != "neo")
{
?>
我想知道你是否听说过莎士比亚, .
他要求得到一束另一个名字的玫瑰化,因为那束闻起来可能会更芳香一些。
对于你,很不幸,我不同意。拒绝进入!
}
?>
--------------------------------------------------------------------------------
在这种情况下, "if" 语句通过判断输入的密码是否正确来反馈相应的两种信息。PHP还允许你“嵌套”条件语句-例如,这是一段有效的PHP代码:
--------------------------------------------------------------------------------
if ($day == "Thursday")
{
if ($time == "12")
{
if ($place == "Italy")
{
$lunch = "pasta";
}
}
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
