Re: Boolean type forced on string assignment inside if statement

From: Date: Fri, 04 Jan 2013 07:56:00 +0000
Subject: Re: Boolean type forced on string assignment inside if statement
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  Groups: php.general 
Request: Send a blank email to php-general+get-320030@lists.php.net to get a copy of this message
2013/1/4 tamouse mailing lists <tamouse.lists@gmail.com> > Bit operators & and | are NOT and should NEVER be confused with > Logical operators && and ||: > > > <?php > /** > * Bit operators in PHP > */ > > $format = "Decimal: %2d Binary: %4b\n"; > > > $a = 4; > $b = 6; > > > echo "Variable \$a:\n"; > printf($format, $a, $a); > > echo "Variable \$b:\n"; > printf($format, $b, $b); > > $c = $a | $b; > echo "Result of OR bit operator\n"; > printf($format, $c, $c); > > $c = $a & $b; > echo "Result of AND bit operator\n"; > printf($format, $c, $c); > > ?> > > > OUTPUT: > ------- > > Variable $a: > Decimal: 4 Binary: 100 > Variable $b: > Decimal: 6 Binary: 110 > Result of OR bit operator > Decimal: 6 Binary: 110 > Result of AND bit operator > Decimal: 4 Binary: 100 > > > Bit operators are not comparing values, they're COMBINING values. > Technically spoken they're comparing bits, whereas boolean operators does the same, but treaten every value as a single bit. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- github.com/KingCrunch

« previous php.general (#320030) next »