Home > php教程 > php手册 > php中++i 与 i++ 的区分详解

php中++i 与 i++ 的区分详解

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:34:05
Original
1364 people have browsed it

  1、++i 的用法(以 a=++i ,i=2 为例)

  先将 i 值加 1 (也就是 i=i+1 ),然后赋给变量 a (也就是 a=i ),

  则最终 a 值等于 3 , i 值等于 3 。

  所以 a=++i 相当于 i=i+1 ,a=i

  2、i++ 的用法(以 a=i++ ,i=2 为例)

  先将 i 值赋给变量 a (也就是 a=i ),然后 i 值加 1 (也就是 i=i+1 ),

  则最终 a 值等于 2 ,i 值等于 3 。

  所以 a=i++ 相当于 a=i , i=i+1

  3、++i 与 i++

  a=++i 相当于 i++ , a=i

  a=i++ 相当于 a=i , i++

  4、++i 与 i++ 单独使用时,相当于 i=i+1

  如果赋给一个新变量,则 ++i 先将 i 值加 1 ,而 i++ 先将 i 赋给新变量。

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template