$a = 1;
$b = $a + $a + +;
Echo $b;
$a = 1;
$b = $a + $a + $a + +;
Echo $b;
Why are all the outputs 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 + + + produces undefined behavior
$a = 1;
echo + + $a + $a + +; May print 4 or 5
?>
http://cn2.php.net/manual/zh/language.operators.increment.php
!--? 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 + + + produces undefined behavior
$a = 1;
Echo + + $a + $a + +;//May print 4 or 5
?>
Do you have anything to do with my question?
Officially, there is no definition of the result when the + + + + + is present at the same time.
Now in the version of PHP 5.3.x windows, your result is 3, $a 2
http://cn2.php.net/manual/zh/ language.operators.increment.php
!--? 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 + + + produces undefined behavior
$a = 1;
Echo + + $a + $a + +;//May print 4 or 5
?>
Do you have anything to do with 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 + + + produces undefined behavior
$a = 1;
echo + + $a + $a + +; May print 4 or 5
?>
Does this answer have anything to do with my question?
The above is an extract from the PHP access document, the Scarlet Letter is the answer to your question.
Mixing + + + produces undefined behavior
Mix + + and + Generate indeterminate behavior
So there's no need to discuss it anymore.
I'm sorry I didn't look carefully
The authorities have already said that there is no definition of the result when the + + + + is present at the same time.
Now the PHP 5.3.x Windows version of your results is 3, $a to 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 + + + produces undefined behavior
$a = 1;
echo + + $a + $a + +; May print 4 or 5
?>
Does this answer have anything to do with my question?