PHP4 practical application experience Article 6. Author: Sun now, you understand 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 complicated and confusing by Sun Sport.
Now you understand that PHP allows you to nest conditional statements. However, if you look at the example to demonstrate this concept, you will agree that it is both complicated and terrible.
--------------------------------------------------------------------------------
<?
If ($ day = "Thursday ")
{
If ($ time = "12 ")
{
If ($ place = "Italy ")
{
$ Lunch = "pasta ";
}
}
}
?>
--------------------------------------------------------------------------------
Fortunately, in addition to the comparison operators that we can use without any restrictions, PHP also provides some logical operators that allow you to aggregate condition statement descriptions. The following table clearly shows these:
Assume that $ 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
$ Delta <= $ omega
False
Well, we can use logical operators to rewrite the code in the above example. do you think the following statements are simpler?
--------------------------------------------------------------------------------
<?
If ($ day = "Thursday" & $ time = "12" & $ place = "Italy ")
{
$ Lunch = "pasta ";
}
--------------------------------------------------------------------------------
Simple and elegant? Yes
Now, you understand 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 complicated and confusing...