时时商务社区

标题: php && 逻辑与运算符使用说明 [打印本页]

作者: 网络通达    时间: 2018-2-14 09:01

            例子:
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
o(︶︿︶)o 唉,很晕,今天问了N多的人。终于把“&&”东西给弄明白怎么回事了
运算符都没有判断就那样写什么意思,哎,原来如果前面的为假。后面的语句就不执行了。免得我们还费劲的写if
这样多简单。。。
//简单说明,如果前面的判断为假后面的则不执行,如果是真,继续执行下面的定义常量操作。
[B]逻辑运算符[/B]
[TR]
例子
名称
结果[/TR]
[TR]
[TD]$a and $b[/TD]
[TD]And(逻辑与)[/TD]
[TD][B]TRUE[/B],如果 $a 与 $b 都为 [B]TRUE[/B]。[/TD][/TR]
[TR]
[TD]$a or $b[/TD]
[TD]Or(逻辑或)[/TD]
[TD][B]TRUE[/B],如果 $a 或 $b 任一为 [B]TRUE[/B]。[/TD][/TR]
[TR]
[TD]$a xor $b[/TD]
[TD]Xor(逻辑异或)[/TD]
[TD][B]TRUE[/B],如果 $a 或 $b 任一为 [B]TRUE[/B],但不同时是。[/TD][/TR]
[TR]
[TD]! $a[/TD]
[TD]Not(逻辑非)[/TD]
[TD][B]TRUE[/B],如果 $a 不为 [B]TRUE[/B]。[/TD][/TR]
[TR]
[TD]$a && $b[/TD]
[TD]And(逻辑与)[/TD]
[TD][B]TRUE[/B],如果 $a 与 $b 都为 [B]TRUE[/B]。[/TD][/TR]
[TR]
[TD]$a || $b[/TD]
[TD]Or(逻辑或)[/TD]
[TD][B]TRUE[/B],如果 $a 或 $b 任一为 [B]TRUE[/B]。[/TD][/TR]
Example #1 逻辑运算符示例
[U]复制代码[/U] 代码如下:


上例的输出类似于:
bool(true)
bool(false)
bool(false)
bool(true)
Another example that might help.

returns the userdata email address, but this

returns false.
The reason is that the two types of ands have a different order of precedence. "&&" is higher than "AND", and the "?:" operator just happens to come between the two. Also, since "||" (or) is actually higher than "AND," you should never mix &&s and ||s with ANDs and ORs without paretheses.
For example:

returns false, but

returns true.
            
            
您可能感兴趣的文章:
  • 用PHP中的 == 运算符进行字符串比较
  • PHP学习 运算符与运算符优先级
  • php合并数组array_merge函数运算符加号与的区别
  • PHP字符串 ==比较运算符的副作用
  • php foreach 使用&(与运算符)引用赋值要注意的问题
  • php下使用strpos需要注意 === 运算符
  • PHP 作用域解析运算符(:\"\"
  • php中的三元运算符使用说明
  • PHP三元运算符的结合性介绍
  • PHP常用特殊运算符号和函数总结(php新手入门必看)
  • php三元运算符知识汇总
  • php 运算符与表达式详细介绍
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2