Home > Backend Development > PHP Tutorial > PHP4 Practical Application Experience Chapter 6_PHP Tutorial

PHP4 Practical Application Experience Chapter 6_PHP Tutorial

WBOY
Release: 2016-07-13 17:28:26
Original
894 people have browsed it

Author: Sun Movement
Now, you have understood that PHP allows you to nest conditional statements. However, if you look at the example used to demonstrate this concept you will agree that it is both complex and scary.
----------------------------------------------- ----------------------------------
if ($day == "Thursday" )
{
if ($time == "12")
{
if ($place == "Italy")
{
$lunch = "pasta";
}
}
}
?>
---------------------------------- --------------------------------------------------
Fortunately, in addition to the comparison operators that we can already use without any restrictions, PHP also provides some logical operators to allow you to group conditional statement descriptions. The following table shows this clearly:
Assume $delta = 12 and $omega = 9
Operator
Meaning
Example
Result
&&
AND
$delta == $gamma && $delta > $omega
True
$delta && $omega False
||
OR
$delta == $gamma | | $delta True
$delta > $gamma || $delta False
!
NOT
!$delta
False
Less than or equal to
$delta


False
Okay, we can rewrite the above example using logical operators Look at the code, is the following expression simpler?
----------------------------------------------- ----------------------------------
if ($day == "Thursday" && $time == "12" && $place == "Italy")
{
$lunch = "pasta";
}
------------- -------------------------------------------------- ------------------
Simple and elegant? Yes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531772.htmlTechArticleAuthor: Sun Movement Now, you have understood that PHP allows you to nest conditional statements. However, if you look at the example used to demonstrate this concept you will agree that it is complex and confusing...
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