Home >Backend Development >PHP Tutorial >PHP中||符号的权重问题

PHP中||符号的权重问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:47:471447browse

<code class="lang-php"><?php $a = 3;
$b = 6;
if($a = 4 || $b = 4){
    $a++;
    $b++;
}
echo $a.$b;
</code></code>

结果为什么是17?

回复内容:

<code class="lang-php"><?php $a = 3;
$b = 6;
if($a = 4 || $b = 4){
    $a++;
    $b++;
}
echo $a.$b;
</code></code>

结果为什么是17?

这个问题和我之前回答过的这个问题 http://segmentfault.com/q/1010000000304873 有点类似。

<code>if($a = 4 || $b = 4)
</code>

把这一行加上括号

<code>if( $a = (4 || $b=4) )
</code>

你就应该能明白了吧。

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