The difference between ++i and i++ in php_PHP tutorial

WBOY
Release: 2016-07-21 15:17:15
Original
1038 people have browsed it

1. Usage of ++i (take a=++i, i=2 as an example)

First add 1 to the i value (that is, i=i+1), and then Assigned to variable a (that is, a=i),

then the final value of a is equal to 3 and the value of i is equal to 3.

So a=++i is equivalent to i=i+1, a=i

2. Usage of i++ (take a=i++, i=2 as an example)

First assign the i value to variable a (that is, a=i), then add 1 to the i value (that is, i=i+1),

Then the final value of a is equal to 2, i value is equal to 3.

So a=i++ is equivalent to a=i, i=i+1

3. ++i and i++

a=++ i is equivalent to i++, a=i

a=i++ is equivalent to a=i, i++

4. When ++i and i++ are used alone, they are equivalent to i=i+ 1

If assigned to a new variable, ++i first adds 1 to the i value, and i++ first assigns i to the new variable.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325767.htmlTechArticle1. Usage of ++i (take a=++i, i=2 as an example) First change i Add 1 to the value (that is, i=i+1), and then assign it to the variable a (that is, a=i), then the final value of a is equal to 3, and the value of i is equal to 3. So...
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!