请问高手,代码问题

WBOY
Release: 2016-06-23 14:03:27
Original
821 people have browsed it

请问高手下面的代码:

$p=10;
$q=8;
if($p++>17 or $q++>7)  //if(false or true)
{
 echo '真值';
}else
{echo '$p='.$p.'$q='.$q;}
 
为什么运行的结果是:真值? 而不是$p=11 $q=7呢?我记得$ee=false or true;var_dump($ee);其值应该是假值而不是真值。这是为什么?


回复讨论(解决方案)

是正确的啊,or满足一个条件就是真,而$ee=(false or true)这样就是真了,前面那是=比or运算级高

你自己测试一下下面几个的真假
$ee=false or true
$ee==false or true
$ee=(false or true)

上面的都是正解哈

if($p++>17 or $q++>7) 
相当于

if($p>17 or $q>7)
{
}

$p++;$q++;

使用变量之后 再加1

你可以试试一楼 二楼的方法,都是正解。

or换成and就是你说的那样的结果了

or   一真俱真
and  一假俱假

if($p++>17 or $q++>7)跟$ee=false or true;不一样吗?为什么?$ee=false or true;它是怎样运算的?

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!