Home >Backend Development >PHP Tutorial >Summary of the differences between OR, || AND and && in PHP_PHP Tutorial

Summary of the differences between OR, || AND and && in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:45953browse

There is no difference in itself, it is a matter of habit, but sometimes it involves issues of operator precedence, and the results will be different, so record them.
For example:

Copy code The code is as follows:

$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)

Because the priority of the assignment operation is higher than AND and OR, the value is assigned first; it is lower than && and ||, so the logical operator is executed first, the logical operation is performed first, and then the value is assigned.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824937.htmlTechArticleThere is no difference in itself, it is a matter of habit, but sometimes it involves issues of operator precedence, the results will be different, record Down. For example: Copy the code The code is as follows: $p = 6 or 0; var_dump...
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