Re: php compiler

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

 



Hodicska Gergely wrote:
$a = 0;
$b = 1;
if ($a = 1 && $b = 0) {
    echo 'true ';
    var_dump($a);
    var_dump($b);
} else {
    echo 'false ';
    var_dump($a);
    var_dump($b);
}
Runing this we get: "true bool(false) int(0)"

Are you sure you posted the example correctly? It outputs this: false bool(false) int(0)


And this output is absolutely correct. Your condition gives new values to $a and $b because you use "=" and not "==". So you do this:

$b = 0;
$a = 1 && $b;

The condition checks the value of $a (which is false) and so you land in the else branch and that's why $b is int(0) and $a is bool(false)

I think you want this:

if ($a == 1 && $b == 0)

--
Bye, K <http://www.ailis.de/~k/> (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger k@xxxxxxxx to get public key)

Attachment: signature.asc
Description: OpenPGP digital signature


[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