Home > Backend Development > PHP Tutorial > php基础有关问题,请指点一下 ,是不是小弟我理解错了

php基础有关问题,请指点一下 ,是不是小弟我理解错了

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:05:40
Original
916 people have browsed it

php基础问题,请指点一下 ,是不是我理解错了?

<br />$c = 10;<br />if ((($a > 0) + ($b > 0) + ($c > 0) + ($d> 0) != 1)) {<br />	message('成功');<br />}else<br />{<br />      message('失败')<br />}<br />
Copy after login


请问,$c是10 为什么在if语句中,却输出了失败??怎么理解? a,b,d都是空的,难道不是这样理解吗($c>0)的时候返回c,
c是10 ,所以 c !=1
难道不应该输出成功吗?
我觉得是我理解错了,请给我指点下难题,谢谢。
------解决方案--------------------
$c = 10;<br />if (((($a > 0) + ($b > 0) + ($c > 0) + ($d> 0)) != 1)) {<br />    message('成功');<br />}else<br />{<br />      message('失败')<br />}
Copy after login

------解决方案--------------------
error_reporting(E_ALL ^ E_NOTICE);<br />$c = 10;<br />echo ($a > 0) + ($b > 0) + ($c > 0) + ($d> 0);
Copy after login
输出1
所以 if ((($a > 0) + ($b > 0) + ($c > 0) + ($d> 0) != 1)) { 不成立 (1 != 1)
因此走 else 分支
------解决方案--------------------
$c = 10;
if ((($a > 0) + ($b > 0) + ($c > 0) + ($d> 0) != 1)) {

$a未定義,所以($a > 0)返回false,轉為int型為0
$b未定義,所以($b > 0)返回false,轉為int型為0
$c=10,所以(10 > 0)返回true,轉為int型為1
$d未定義,所以($d > 0)返回false,轉為int型為0

語句重寫之後就變成了
if((0+0+1+0)!=1){

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