note 110630 deleted from language.operators.logical by googleguy

From: Date: Wed, 14 Nov 2012 19:08:49 +0000
Subject: note 110630 deleted from language.operators.logical by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191934@lists.php.net to get a copy of this message
Note Submitter: m_lajos at hotmail dot com ---- Watch out when working with booleans! <?php $x = true; $y = (/* some condition, that returns boolean true or false */); $x = $x && $y; // $x remains bool( true or false ) $x = $x & $y; // $x becomes int( 0 or 1 ) // let's restart... $x = true; // Let's say, you want to shorthand the upper codes in for example a form validation code: $x &= $y; // same as $x = $x & $y; | this will make $x an int! // There is no shorthand for && sign addition though, like below: $x &&= $y; // The same is with the other logic opeator: or( || ) // xor doesn't even have a doubled version: ^^ // To overcome this absence of logic operators simply add another line at the end which will transform your int back to boolean: $x = (bool)$x; ?>

« previous php.notes (#191934) next »