note 30637 added to control-structures
| From: | ian at rack1 dot php dot net | Date: | Mon, 24 Mar 2003 16:26:19 +0000 |
| Subject: | note 30637 added to control-structures | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45741@lists.php.net to get a copy of this message | ||
In response to LexZEUS:
If you used the same code with | instead of || and & instead of && (as follows)
function lex1()
{
print "Hello";
return 1;
}
function lex2()
{
print "World";
return 1;
}
if (lex1() | lex2()) {}
if (
@function1() &
@function2() &
@function3() &
@function4() &
@function5()) {}
All functions would be executed before the final boolean is returned.
Although || and && are more useful (efficient and easy to understand), | and & are
normally used when some functions _have_ to be executed even if one fails.
a good example is:
if (isset($a) && $a == 'hello')
echo $a;
if (isset($b) & $b == 'world')
echo $b;
while the first 'if' will always be okay, the second will return an error if $b had not
been set as it will still compare $b to 'world' (which should return 'false' and
a warning)
--
http://www.php.net/manual/en/control-structures.php
http://master.php.net/manage/user-notes.php?action=edit+30637
http://master.php.net/manage/user-notes.php?action=delete+30637
http://master.php.net/manage/user-notes.php?action=reject+30637