Q & a $ a = 1;
$ B = $ a + $ a ++;
Echo $ B;
$ A = 1;
$ B = $ a + $ a ++;
Echo $ B;
Why are all output 3?
Reply to discussion (solution)
Http://cn2.php.net/manual/zh/language.operators.increment.php
$ A = 3*3% 5; // (3*3) % 5 = 4
$ A = true? 0: true? 1: 2; // (true? 0: true )? 1: 2 = 2
$ A = 1;
$ B = 2;
$ A = $ B + = 3; // $ a = ($ B + = 3)-> $ a = 5, $ B = 5
// Mixing ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Http://cn2.php.net/manual/zh/language.operators.increment.php
$ A = 3*3% 5; // (3*3) % 5 = 4
$ A = true? 0: true? 1: 2; // (true? 0: true )? 1: 2 = 2
$ A = 1;
$ B = 2;
$ A = $ B + = 3; // $ a = ($ B + = 3)-> $ a = 5, $ B = 5
// Mixing ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to my question?
The official website has already said that when both ++ and ++ exist, there is no definition of the result.
In php 5.3.x windows, your result is 3, and $ a is 2.
Http://cn2.php.net/manual/zh/language.operators.increment.php
$ A = 3*3% 5; // (3*3) % 5 = 4
$ A = true? 0: true? 1: 2; // (true? 0: true )? 1: 2 = 2
$ A = 1;
$ B = 2;
$ A = $ B + = 3; // $ a = ($ B + = 3)-> $ a = 5, $ B = 5
// Mixing ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to my question?
Http://cn2.php.net/manual/zh/language.operators.increment.php
$ A = 3*3% 5; // (3*3) % 5 = 4
$ A = true? 0: true? 1: 2; // (true? 0: true )? 1: 2 = 2
$ A = 1;
$ B = 2;
$ A = $ B + = 3; // $ a = ($ B + = 3)-> $ a = 5, $ B = 5
// Mixing ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to my question?
The above is extracted from the php access document. The Red Letter is the answer to your question.
Mixing ++ and + produces undefined behavior
Mixed ++ and ++ produce uncertain behaviors
So there is no need to discuss it.
Sorry, I didn't take it seriously.
The official website has already said that when both ++ and ++ exist, there is no definition of the result.
In php 5.3.x windows, your result is 3, and $ a is 2.
Http://cn2.php.net/manual/zh/language.operators.increment.php
$ A = 3*3% 5; // (3*3) % 5 = 4
$ A = true? 0: true? 1: 2; // (true? 0: true )? 1: 2 = 2
$ A = 1;
$ B = 2;
$ A = $ B + = 3; // $ a = ($ B + = 3)-> $ a = 5, $ B = 5
// Mixing ++ and + produces undefined behavior
$ A = 1;
Echo ++ $ a + $ a ++; // may print 4 or 5
?>
Is your answer related to my question?