Home  >  Article  >  php教程  >  那些年,我们追过的PHP自加自减运算(2)

那些年,我们追过的PHP自加自减运算(2)

WBOY
WBOYOriginal
2016-06-13 09:33:03839browse

-----------------------------------------------------------------------------------------

先来一段例子,来引出重点。

$a = true;

echo $a++;

echo $a + 1;

$b = 'c';

echo $b++;

echo $b++;

---------------------@chenwei  --------------------------------

上面四个输出你是否知道正确答案呢,下面是总结的一些规律,各位也可以亲自动手实验。

1. 布尔型不参与 ++ 运算, 不会进行类型转换而参与自增。所以第一个输出是1。

2. 布尔型参与算数运算如+,-,会自动进行类型转换,所以第二个输出是2。

3. PHP中字符串++表示升序,所以第三个输出是c, 第四个输出是d。

-----------------------------------------------------------------------------------------

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