Re: Simple logic but can't get it right

From: Date: Thu, 09 Nov 2006 06:11:00 +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-244421@lists.php.net to get a copy of this message
comments inline Choy, Wai Yew wrote:
<?php $a = 1;
            $id = "outside";
            
  this if statement is false, because $a == 1
            if ($a == 0) { 
                  
                        $b = 1;
                        $id = "a";
                  
            }
this if statement is true, because $b has not been defined, and is evaluating to 0
            elseif ($b == 0) {
                  
                        $c = 1;
                        $id = "b";
                  
            }
this statement never gets reached, because the previous statement was true
            elseif ($c == 0){
                  
                        $d = 1;
                        $id = "c";
                  
            }
            
echo "ID = $id<br>"; //Output is "b"...WHY?? It should be "outside"... ?>


« previous php.general (#244421) next »