Re: Bitwise operation giving wrong results
| From: | Ashley Sheridan | Date: | Thu, 30 Oct 2008 00:29:58 +0000 |
| Subject: | Re: Bitwise operation giving wrong results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282594@lists.php.net to get a copy of this message | ||
On Wed, 2008-10-29 at 20:01 -0400, sean greenslade wrote:
> I have the following code as a test:
> <?php
> $a = $_GET['a'];
> $b = $_GET['b'];
> echo $a . " & " . $b . " = ";
> $out = $a & $b;
> echo $out;
> //echo 15 & 2;
> ?>
>
> if I set a to 15 and b to 2 in the URL like so:
>
> test.php?a=15&b=2
>
> it outputs zero as the answer. When I run the hard-coded '&' operation (the
> commented out echo), it returns 2. I'm stumped.
In PHP a boolean true also equates to 1. You are using the & operator
though, instead of the && which I think you're looking for. They both do
different things. Sorry, it's late and I've been befriending mr Jack
Daniels a little tonight, so forgive me if my answer is as close to what
you were looking for as is 42 (life the universe and everything) to The
Question.
Ash
www.ashleysheridan.co.uk