Home  >  Article  >  Backend Development  >  PHP4 Practical Application Experience (6)_PHP Tutorial

PHP4 Practical Application Experience (6)_PHP Tutorial

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

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 describe conditional statements Gather together. The following table clearly shows these:


Assume $delta = 12 and $omega = 9

Operator
Meaning
Example
Result

&&
AND
$delta == $gamma && $delta > $omega
True

$delta && $omega < $omega
False

||
OR
$delta == $gamma || $delta < $omega
True

$delta > $gamma || $delta < $ omega
False

!
NOT
!$delta
False

< =
less than or equal to
$delta < = $ omega
False


OK, we can rewrite the code of the above example using logical operators. Look, is the following expression simpler?

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

if ( $day == "Thursday" && $time == "12" && $place == "Italy")
                                                                                                -------------------------------------------------- --------------------------
Simple and elegant? Yes



http://www.bkjia.com/PHPjc/316292.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/316292.html

TechArticle

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