Home  >  Article  >  Backend Development  >  Relational operators && and || in php

Relational operators && and || in php

不言
不言Original
2018-04-16 11:23:442581browse

This article introduces the relational operators && and || in PHP, which has certain reference value. Now I share it with you. Friends in need can refer to it

这两个是php 中的关系运算符。
  php中的关系运算符有:&&(and)、||(or)、xor(亦或)、!(非)、

  名称    关系     示例             结果
  and    与       $x and $y    如果 $x 和 $y 都为 true,则返回 true。    
  or       或       $x or $y       如果 $x 和 $y 至少有一个为 true,则返回 true。
  xor     异或    $x xor $y     如果 $x 和 $y 有且仅有一个为 true,则返回 true。    
  &&    与        $x && $y    如果 $x 和 $y 都为 true,则返回 true。    
  ||        或        $x || $y        如果 $x 和 $y 至少有一个为 true,则返回 true。
    !      非         !$x              如果 $x 不为 true,则返回 true。

【注解】&&是表示“和”“与”的关系,两遍都为真是结果才为真。

          | |表示”或“的关系,只要有有一个为真结果就为真。
               !(非)是将false转为true      true转为false

【难点】xor(亦或)是指两边只有一个为真   整个表达式的结果才是真  否则都是false
              1 xor 1  =false     0 xor 0  =false    0 xor 1 =true

Related recommendations:

The difference between && and & operations in php

         


The above is the detailed content of Relational operators && and || in php. For more information, please follow other related articles on the PHP Chinese website!

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