note 24511 added to control-structures
| From: | simon at invalid dot com | Date: | Tue, 20 Aug 2002 04:11:33 +0000 |
| Subject: | note 24511 added to control-structures | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35232@lists.php.net to get a copy of this message | ||
There are something to remind beginners:
if(-1)
echo "(-1 OK) ";
else
echo "(-1 fail) ";
if("")
echo "(\"\" OK) ";
else
echo "(\"\" fail) ";
if(0)
echo "(0 OK) ";
else
echo "(0 fail) ";
// result: (-1 OK) ("" fail) (0 fail)
In addition, if you want check if $a,$b and $c are all the same, you should have the condition like
that:
if($a==$b && $a==$c) {
//do somthing;
}
else {
//do something;
}
Moreover, in (condition1 && condition2), if condition1 is FALSE, then condition2 will not be
checked/executed, in the case, if want to executed condition2, use (condition1 & condition2)
instead
The case is similar in (condition1 || condition2), if you want to execute condition2 no matter
condition1 is TRUE or not, use (condition1 | condition2)
Hope can help you
--
http://www.php.net/manual/en/control-structures.php
http://master.php.net/manage/user-notes.php?action=edit+24511
http://master.php.net/manage/user-notes.php?action=delete+24511
http://master.php.net/manage/user-notes.php?action=reject+24511