欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php && 邏輯與運算符使用說明

 更新時間:2010年03月04日 19:02:25   作者:  
如果前面的判斷為假后面的則不執(zhí)行,如果是真,繼續(xù)執(zhí)行下面的操作。
例子:
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());

o(︶︿︶)o 唉,很暈,今天問了N多的人。終于把“&&”東西給弄明白怎么回事了

運算符都沒有判斷就那樣寫什么意思,哎,原來如果前面的為假。后面的語句就不執(zhí)行了。免得我們還費勁的寫if

這樣多簡單。。。

//簡單說明,如果前面的判斷為假后面的則不執(zhí)行,如果是真,繼續(xù)執(zhí)行下面的定義常量操作。
邏輯運算符
例子 名稱 結(jié)果
$a and $b And(邏輯與) TRUE,如果 $a 與 $b 都為 TRUE
$a or $b Or(邏輯或) TRUE,如果 $a 或 $b 任一為 TRUE
$a xor $b Xor(邏輯異或) TRUE,如果 $a 或 $b 任一為 TRUE,但不同時是。
! $a Not(邏輯非) TRUE,如果 $a 不為 TRUE。
$a && $b And(邏輯與) TRUE,如果 $a 與 $b 都為 TRUE。
$a || $b Or(邏輯或) TRUE,如果 $a 或 $b 任一為 TRUE。

Example #1 邏輯運算符示例
復(fù)制代碼 代碼如下:

<?php
// 下面的 foo() 不會被調(diào)用,因為它們被運算符“短路”了。
$a = (false && foo());
$b = (true || foo());
$c = (false and foo());
$d = (true or foo());
// "||" 的優(yōu)先級比 "or" 高
$e = false || true; // $e 被賦值為 (false || true),結(jié)果為 true
$f = false or true; // $f 被賦值為 false [Altair注:"=" 的優(yōu)先級比 "or" 高]
var_dump($e, $f);
// "&&" 的優(yōu)先級比 "and" 高
$g = true && false; // $g 被賦值為 (true && false),結(jié)果為 false
$h = true and false; // $h 被賦值為 true [Altair注:"=" 的優(yōu)先級比 "and" 高]
var_dump($g, $h);
?>

上例的輸出類似于:
bool(true)
bool(false)
bool(false)
bool(true)

Another example that might help.

<?php
(isset($panelemail) && !empty($panelemail) ? $panelemail : $userdata['email']);
?>
returns the userdata email address, but this

<?php
(isset($panelemail) AND !empty($panelemail) ? $panelemail : $userdata['email']);
?>
returns false.

The reason is that the two types of ands have a different order of precedence. "&&" is higher than "AND", and the "?:" operator just happens to come between the two. Also, since "||" (or) is actually higher than "AND," you should never mix &&s and ||s with ANDs and ORs without paretheses.

For example:

<?php
true && false || false
?>
returns false, but

<?php
true AND false || false
?>
returns true.

相關(guān)文章

最新評論