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

PHP中||符号的权重问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:47:47
Original
1438 people have browsed it

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

结果为什么是17?

回复内容:

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

结果为什么是17?

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

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

把这一行加上括号

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

你就应该能明白了吧。

Related labels:
php
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