Home >Backend Development >PHP Tutorial >PHP4 Practical Application Experience (3)_PHP Tutorial

PHP4 Practical Application Experience (3)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 16:03:06836browse

Author: Sun Movement

In PHP, the simplest form of conditional statement is the "if" statement, which generally looks like the following:
--------------- -------------------------------------------------- ---------------
if (condition)
{
do this!
}
---------- -------------------------------------------------- ------------------
The "condition" here is a description of a condition. PHP will get either "true" or "false" after judgment. value. If it is true, all the PHP code in the curly brackets will be executed. On the contrary, if it is false, the code in the curly brackets will be ignored and execution will continue with the lines after the "if" statement structure block.


We will show you how the "if" statement works by adding an authentication example to the "login.php" script above. Access is only allowed if the username entered by the user is "neo".


----------------------------------------- ---------------------------------------
< html>
< ; head>
< basefont face="宋体">
< /head>

< body>
< center>

< ?

// Check the name and feedback the corresponding information
if ($name == "neo")
{

?>
< font face=" Arial" size="-1">
Welcome to the matrix, Neo.
< p>
Maybe you were forced to do this by force,,,oh, illicit video! < /font>

< ?
}
?>


< ?
//If the password is wrong
if ($name != "neo")
{
?>


< font face="Arial" size="-1">
I want to know Have you ever heard of Shakespeare, < ? echo $name; ?>.
< p>
He asked for a bouquet of roses by another name because that bouquet might smell more fragrant Some.
< p>
Unfortunately for you, I disagree. Entry refused!
< /font>

< ?
}
?>


< /center>
< /body>

< /html>
---------------------------------------- ---------------------------------------------
In this case Below, the "if" statement feeds back the corresponding two pieces of information by judging whether the entered password is correct. PHP also allows you to "nest" conditional statements - for example, this is a valid piece of PHP code:

--------------------- -------------------------------------------------- -------
< ?

if ($day == "Thursday")
{
if ($time == "12")
{
if ($place == "Italy")
{
$lunch = "pasta";
}
}
}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316405.htmlTechArticleAuthor: Sun Movement In PHP, the simplest form of conditional statement is the if statement, which generally looks like the following: -------------------------------------------------- ----------------------------------...
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