Home > Backend Development > PHP Tutorial > php && 逻辑与运算符使用说明

php && 逻辑与运算符使用说明

WBOY
Release: 2016-06-23 13:35:36
Original
890 people have browsed it

 

// 下面的 foo() 不会被调用,因为它们被运算符“短路”了。 

$a = (false && foo()); 

$b = (true || foo()); 

$c = (false and foo()); 

$d = (true or foo()); 

// "||" 的优先级比 "or" 高 

$e = false || true; // $e 被赋值为 (false || true),结果为 true 

$f = false or true; // $f 被赋值为 false [Altair注:"=" 的优先级比 "or" 高] 

var_dump($e, $f); 

// "&&" 的优先级比 "and" 高 

$g = true && false; // $g 被赋值为 (true && false),结果为 false 

$h = true and false; // $h 被赋值为 true [Altair注:"=" 的优先级比 "and" 高] 

var_dump($g, $h); 

?> 

巧用运算符这个特性可以减少使用IF 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template