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

            $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"...

?>




--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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

Reply via email to