Re: Simple logic but can't get it right
| From: | Myron Turner | Date: | Thu, 09 Nov 2006 18:04:31 +0000 |
| Subject: | Re: Simple logic but can't get it right | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244435@lists.php.net to get a copy of this message | ||
You are testing unset variables. This will work as you expect:
<?php
$a = 1;
$id = "outside";
if ($a == 0) {
$b = 1;
$id = "a";
}
elseif (isset($b) && $b == 0) {
$c = 1;
$id = "b";
}
elseif (isset($c) && $c == 0){
$d = 1;
$id = "c";
}
echo "ID = $id<br>"; //Output is "b"...WHY?? It should be "outside"...
?>
Choy, Wai Yew wrote:
Hi gurus, I've the following piece of PHP code....It is a simple logic but I can't get it right....The output result of $id is "b"!!...It should be "outside", right?? I think it is the variable $b....Coz' it depend on the previous check ( if ($a == 0) ) for the value... If this is the case, how can I get this logic works?? Thanks a million, Choy <?php-- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/$a = 1;$id = "outside";if ($a == 0) {$b = 1;$id = "a";}elseif ($b == 0) {$c = 1;$id = "b";}elseif ($c == 0){$d = 1;$id = "c";}echo "ID = $id<br>"; //Output is "b"...WHY?? It should be "outside"... ?>