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

WBOY
Release: 2016-06-23 13:50:32
Original
1014 people have browsed it

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


请问,$c是10 为什么在if语句中,却输出了失败??怎么理解? a,b,d都是空的,难道不是这样理解吗($c>0)的时候返回c,
c是10 ,所以 c !=1
难道不应该输出成功吗?
我觉得是我理解错了,请给我指点下难题,谢谢。


回复讨论(解决方案)

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

error_reporting(E_ALL ^ E_NOTICE);$c = 10;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){

谢谢,原来是返回false和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!