note 97559 deleted from function.print by danbrown

From: Date: Mon, 26 Apr 2010 14:29:50 +0000
Subject: note 97559 deleted from function.print by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168654@lists.php.net to get a copy of this message
Note Submitter: peev dot alexander at gmail dot com ---- (As a response to user at example dot net 25-Aug-2008 04:47) There is an easier way (than bracket wrapping) to have all print statements in an if condition executed while keeping them separated: <?php if (print("foo") and print("bar") and print("baz")) { // "foo" and "bar" and "baz" have been printed } ?> or <?php if (print("foo") xor print("bar") xor print("baz")) { // "foo" and "bar" and "baz" have been printed } ?> This is true, because of the low precedence of the 'or', 'and', and 'xor' operators. If you use the 'or' operator instead of 'and' or 'xor', only "foo" will be printed, because print always returns int(1) (which obviously evaluates to true), and this will stop further evaluation. Of course if you use the 'xor' operator and have an even amount of if statements, the if-block will not execute. You could also use it like this: <?php $print_remains = false; if (print("foo") and $print_remains and print("bar") and print("baz")) { // This if-block will not execute } ?> This will only print "foo", and will not execute the if-block. Hope this helps someone.

« previous php.notes (#168654) next »