Home > php教程 > php手册 > php中OR与|| AND与的区别总结

php中OR与|| AND与的区别总结

WBOY
Release: 2016-06-06 20:27:08
Original
1869 people have browsed it

以下是对php中OR与|| AND与的区别进行了详细的总结介绍,需要的朋友可以过来参考下

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

复制代码 代码如下:


$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的高,所以先赋值;比&&和||的低,所以逻辑运算符先执行,先逻辑运算,再赋值。

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template