PHP4 Practical Application (6)

Source: Internet
Author: User
Tags logical operators
Now, you've learned that PHP allows you to nest conditional statements. However, if you look at the example that is used to demonstrate this concept, you will agree that it is both complex and frightening.


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

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

?>
--------------------------------------------------------------------------------
Fortunately, in addition to the comparison operators we have been able to use without any restrictions, PHP also provides a number of logical operators that allow you to assemble conditional statement descriptions. These are clearly illustrated in the table below:


Assume $delta = 12 and $omega = 9

Operator
Significance
Example
Results

&&
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


Well, we can rewrite the code for the above example with the logical operator, and you see, is the following statement simpler?

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

if ($day = = "Thursday" && $time = = "" && $place = = "Italy")
{
$lunch = "pasta";
}
--------------------------------------------------------------------------------
Is it simple and elegant? Yes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.