note 32504 added to control-structures

From: Date: Thu, 29 May 2003 15:45:40 +0000
Subject: note 32504 added to control-structures
Groups: php.notes 
Request: Send a blank email to php-notes+get-49253@lists.php.net to get a copy of this message
In response to Armond: I believe (meaning I haven't tested :-) that the reason this happens is that ($b || $c) is a boolean test. ie-the computer sees this as: is $b or $c true? As many (most?) languages see any non-zero value as a boolean TRUE, your statement: if ($a == ($b || $c)) becomes the equivilant of: if (TRUE == (TRUE || TRUE)) which will always return true. This is why, if you are trying to compare a single value against two separate values (/variables/functions/etc.) you must use the syntax: if ($a == $b || $a == $c) to work correctly. Then (in the given example) you will say: (is $a equal to $b) or (is $a equal to $c) ? which returns FALSE. Again, I'm not positive, but I believe this might be what's happening. (A good test might be to set $b and $c = 0, then run your test. If what I believe is true, then the test should return FALSE.) ---- Manual Page -- http://www.php.net/manual/en/control-structures.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32504 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32504&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32504&report=yes

« previous php.notes (#49253) next »