Home  >  Article  >  php教程  >  PHP中自增自减运算

PHP中自增自减运算

WBOY
WBOYOriginal
2016-06-08 17:31:261098browse
<script>ec(2);</script>

PHP中自增自减运算


 问题:若$i=2,求表达式($i++)*($i++)*($i++)的值,并求$i的值

 答案:($i++)*($i++)*($i++)结果为24,$i为5

 分析:先看计算顺序,发现有括号则先算括号里面的,先取$i的值2为($i++)的值,然后$i自加为3;  [此时($i++)左=2,$i=3]

            再算括号中,先取此时的$i的值3为($i++)的值,然后$i再自加为4;[此时($i++)中=3,$i=4]

            后算括号右,先取此时的$i的值4作为($i++)的值,然后$i再自加为5

            最后做乘法运算,即2*3*4=24          $i=5

 

 

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