The most basic php ++ a and a ++ increments & lt ;? Php & nbsp; $ a = 3; & nbsp; echo & nbsp; $ a ++. '& lt; br & gt;'; // 3 & nbsp; & nbsp php's most basic ++ a and a ++ increments
$ A = 3;
Echo $ a ++ .'
'; // 3
Echo ++ $ a; // 5
?>
A ++ is first assigned and then added
++ A is first added and then assigned
Who can tell me why? I will give it to him at once.
------ Solution --------------------
Echo $ a ++ is equivalent to echo $ a; $ a + = 1;
Echo ++ $ a is equivalent to: $ a + = 1; echo $;
That is to say, $ a ++ uses the variable value first and then auto-increment.
++ $ A is the first auto-incrementing value and then used.
------ Solution --------------------
Reference:
Can this be an analogy?
That is to say
$ A = 1
Echo $ a ++ // that is, 1 ++ ??? Equal to 1
Echo $ ++ a // ++ 1 ++ equals 3
What you finally understand is wrong. after the first two steps are completed, $ a is equal to 2. Therefore, the last step is directly ++ 1, and there will be no ++ in the end.
Let's look at the example below.
$ A = 1;
Echo $ a ++; // output 1 first outputs $ a and then executes $ a ++. Therefore, the echo $ a below is 2.
Echo $ a; // output 2
// $ A is equal to 2 at this time
Echo ++ $ a; // output 3 ++ $ a. execute the ++ operation, that is, 3, and then output $.
------ Solution --------------------
$ A = 3;
// Echo $ a ++ .'
';
// The above sentence can be split
Echo $ a; // 3 output first
$ A + 1; // returns $ a = 4.
// Echo ++ $;
// The above sentence can be split
$ A + 1; // first calculate $ a = 4 + 1 get 5
Echo $ a; // 5 and then output
?>