简体   繁体   English

如果不使用减量/增量

[英]if not working with decrement/increment

Hi I´m new in php and in one book i found this: 嗨,我是php新手,在一本书中,我发现了这一点:

$x = 0;    
if ($x-- == 0) echo $x;

in book they write it should write -1 to my page, because decremenet was done after comparison and before the command exho was executed. 在他们写的书中,应该在我的页面上写-1,因为decremenet是在比较之后和执行exho命令之前完成的。 I understand why it is that, but when I type it into my editor it's giving me error because it's understanding $x-- as one and $x as another variable. 我知道为什么会这样,但是当我在编辑器中键入它时,由于我将$ x理解为一个变量而将$ x理解为另一个变量,这给了我错误。 Where's problem? 哪里有问题

Basic Steps : 基本步骤:

Step 1: (get Notepad++ ) 步骤1:(获取Notepad ++

Go to http://notepad-plus-plus.org/ and download Notepad++ . 转到http://notepad-plus-plus.org/并下载Notepad ++
Notepad++ is a free (as in "free speech" and also as in "free beer") source code editor and Notepad replacement that supports several languages. Notepad ++是免费的(如“言论自由”,也如“免费啤酒”)源代码编辑器和支持多种语言的Notepad替换。 Running in the MS Windows environment, its use is governed by GPL License. 它运行在MS Windows环境中,其使用受GPL许可证约束。

Step 2: (type the code) 步骤2 :(输入代码)

type and save as "filename.php" in "www directory" 在“ www目录”中键入并另存为“ filename.php”

<?php

$x = 0;    
if ($x-- == 0) echo $x;

?>

Step 3: (enJoy !) 步骤3: (enJoy!)

Check the result 检查结果

Expected Output : -1 // this is what i got! 预期输出:-1 //这就是我得到的! :D :D

$x-- is postdecrement that is the $x value will be still 0. when you went away from the statement then only the $x value should be change. $ x--是递减的,即$ x的值仍为0。当您离开语句时,仅应更改$ x的值。 so if statement is working fine. 因此,如果语句运行正常。 the echo value will be -1. 回声值将为-1。

7-isnotbad answer is correct. 7-isnotbad答案是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM