RE: Simple logic but can't get it right

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since you don't declare variables in PHP, they are preinitialized for you as
'false' or '0'

So since $b is not set initially, it is 0 therefore second elseif passes. 

> -----Original Message-----
> From: Choy, Wai Yew [mailto:waiyew.choy@xxxxxxxxxx] 
> Sent: Wednesday, November 08, 2006 9:34 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Simple logic but can't get it right
> 
> 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
> 
>  
> 
>             $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"...
> 
>  
> 
>  
> 
>  
> 
> ?>
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux