note 6706 deleted from control-structures by jimw
| From: | jimw@php.net | Date: | Thu, 20 Dec 2001 23:10:44 +0000 |
| Subject: | note 6706 deleted from control-structures by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23543@lists.php.net to get a copy of this message | ||
New users often find testing multiple conditions within an IF statement or a looping construct (like
WHILE, FOR, etc...) difficult.
One way to make this task easier is to make sure to bracket each statement that you are testing.
For example:
# Simple tests need no brackets
if ($x || $y)
# This test does not require brackets
# but they will improve readability
if ($x || $y && $z)
# See the difference?
if (($x || $y) && $z)
# If this code is not bracketed
# you may not get the expected results
if ( $a || $x xor $y || $z)
# Bracket let PHP know exactly what you mean
if ( ($a || $x) xor ($y || $z))
if ( $a || ($x xor $y) || $z)
Good Luck!