Home  >  Article  >  Backend Development  >  php中OR与|| AND与&&的区别总结_php技巧

php中OR与|| AND与&&的区别总结_php技巧

WBOY
WBOYOriginal
2016-05-17 08:54:22999browse

本身没有区别,习惯问题 ,但是有时候牵涉到运算符优先级的问题,结果会不同,记录下。
例如:

复制代码 代码如下:

$p = 6 or 0;
var_dump($p);//int(6)

$p = 6 || 0;
var_dump($p);//bool(true)

$p = 6 and 0;
var_dump($p); //int(6) 

$p = 6 && 0;
var_dump($p); //bool(false) 

因为赋值运算的优先级比AND和OR的高,所以先赋值;比&&和||的低,所以逻辑运算符先执行,先逻辑运算,再赋值。

Statement:
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