For an introduction to the usage of ++i and i++ in PHP, friends in need can refer to it.
For an introduction to the usage of ++i and i++ in php, friends in need can refer to 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 assign it to the variable a (that is, a=i), then the final a value is equal to 3, and the i value is equal to 3. Therefore, 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 the variable a (that is, a=i), then add 1 to the i value (that is, i=i+1), then the final a value is equal to 2 and the i value is equal to 3. Therefore, 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. |